////////////////////////////////////////////////////
//	File:		GamePlayState.cpp
//	Class:		SGP
//	Updated:	3/8/2012
//	Author:		Roc Myers
//	Purpose:	To contain all Gameplay related code
////////////////////////////////////////////////////
#include "GamePlayState.h"
#include "MainMenuState.h"
#include "BaseMessage.h"
#include "Messages\CharacterDeathMessage.h"
#include "Messages\CreateCharacterMessage.h"
#include "Messages\WinTileEventMessage.h"
#include "MessagingSystem.h"
#include "SGD Wrappers\SGD_Math.h"
#include <random>
#include <ctime>
#include "AnimationManager.h"
#include "ParticleManager.h"
#include "tinyxml\tinyxml.h"
#include "Messages\CreateItemMessage.h"
#include "Messages\TakeCharacterMsg.h"
#include "TutorialPlayState.h"

GamePlayState* GamePlayState::pInstance = nullptr;

GamePlayState::GamePlayState(void)
{
	BGMID		= -1;
	FontID		= -1;
	ShopBGM		= -1;
	CursorID	= -1;
	tileBmpID	= -1;
	declineID	= -1;
	acceptID	= -1;
	errorID		= -1;
	moveID		= -1;
	sunnyID		= -1;
	twentyID	= -1;
	reinforceID = -1;
	gotchaID	= -1;
	drinkID		= -1;
	inhalerID	= -1;
	hideID		= -1;
	chickenID	= -1;
	pansyID		= -1;
	drawID		= -1;
	biteID		= -1;
	noneID		= -1;			
	imID		= -1;
	woundID		= -1;
	healID		= -1;
	allergyID	= -1;
	boltID		= -1;
	fireID		= -1;
	waterID		= -1;
	boingID		= -1;
	thudID		= -1;
	swingID		= -1;
	throwID		= -1;
	splashID	= -1;
	crackerID	= -1;
	tennisID	= -1;
	rhurtID		= -1;
	whurtID		= -1;
	khurtID		= -1;
	ahurtID		= -1;
	ShopBmp		= -1;
	MPotions	= 0;
	HPotions	= 0;
	Inhalers	= 0;
	ShopChoice	= 0;
	scaleInc	= 0.0f;
	MS			= nullptr;
	myManager	= nullptr;
	gameGrid	= nullptr;
	activeTile = nullptr;
	RainSound = -1;
	SnowSound = -1;
	RWpn = true;
	RArm = true;
	KWpn = true;
	KArm = true;
	AWpn = true;
	AArm = true;
	WWpn = true;
	WArm = true;
	ArchEquip = false;
	KnEquip = false;
	WizEquip = false;
	RgEquip = false;
	FadeWindowImg = -1;
	CurAttacker = nullptr;
	CurDefender = nullptr;
	Explosion = -1;
	Chars = false;
	Turn = true;
	ShowTurn = false;
	Timer = 0.0f;
	blankRectID = -1;
	TennisballID = -1;
	PlungerID = -1;
	fireCrackerID = -1;
	WaterBalloonID = -1;
	PanelID = -1;
	Throw = true;
	SpellHit = false;
	playVoice = false;
	fbHurt = true;
	kdeathID = -1;
	rdeathID = -1;
	wdeathID = -1;
	adeathID = -1;
	this->mapToUse = -1;
}


GamePlayState::~GamePlayState(void)
{
}

GamePlayState* GamePlayState::GetInstance(void)
{
	if(pInstance == nullptr)
		pInstance = new GamePlayState();

	return pInstance;
}

void GamePlayState::DeleteInstance()
{
	if(pInstance != nullptr)
	{
		delete pInstance;
		pInstance = nullptr;
	}
}

void GamePlayState::Enter(void)
{
	// Seed random number generator
	srand((unsigned int)time(0));

	// Set variables
	Paused = false;
	StartGame = false;
	Resume = true;
	Items = false;
	Equip = false;
	InProgress = false;
	ShopMenu = false;
	Movement = false;
	Save = false;
	Load = true;
	LoadFailed = false;
	Command = false;
	Attack = false;
	StartChoice = 0;
	ItemMenu = false;
	StatsMenu = false;
	Chars = false;
	ItemChoice = 0;
	CmndChoice = 0;
	File = 0;
	gameWon = false;
	gameWon2 = false;
	gameWonTimer = 0;
	DiceRolled = false;
	DiceShown = false;
	DiceTime1 = 0.0f;
	DiceTime2 = 0.0f;
	DShownTime = 0.0f;
	diceRECT.left = 0;
	diceRECT.top = 0;
	diceRECT.bottom = 0;
	diceRECT.right = 0;
	HPotions = 0;
	MPotions = 0;
	Inhalers = 0;
	cursorX = 0;
	cursorY = 0;
	abilityMenu = false;
	abilitySelection = 0;
	abilityTargeting = false;
	playerTurn = true;
	this->ai = AIManager::GetInstance();
	SelectingaTile = false;
	SelectingCount = 0;
	WeatherTime = 0;
	WeatherRand = rand() % 5 + 2;
	WeatherType = 0;
	TotalDamage = 0;
	SizeOfParty = 0;
	TotalHealing = 0;
	healingTimer = 0.0f;
	healingShit = false;
	preLeftSelection = 0;
	preRightSelection = 0;
	prebattle = false;
	gameLost = false;
	tutStart = false;
	tutChoice = 0;
	FadeWindow.left = 0;
	FadeWindow.top = 0;
	FadeWindow.right = Game::GetInstance()->GetWinWidth();
	FadeWindow.bottom = Game::GetInstance()->GetWinHeight();
	mapSelection = 0;
	mapToUse = -1;
	mapSelectBool = false;
	Modifier = 0.0f;
	map2Unlocked = false;
	map3Unlocked = false;
	AtkTypeStorage = -1;
	Shotspeed = 0.0f;
	Shotspeed2 = 0.0f;
	cursorMoved = false;
	AImoving = false;
	multishotbullshitfix = false;
	//currWeather = "Sun.xml";

	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;
	this->aiTargeting = false;

	actionWindow = false;
	actionWindowTimed = false;
	actionWindowTimer = 0.0f;
	actionWindowEnum = -1;

	aiTarget = nullptr;
	aiSelected = nullptr;

	prebattle = false;

	twentyRender = false;
	twentyTimer = 0.0f;
	twentyPosX = -99;

	selected.clear();
	selectFrom.clear();
	enemyInventory.clear();
	Inventory.clear();

	// Load Assets
	BGMID		= CSGD_XAudio2::GetInstance()->MusicLoadSong(_T("resource/09 - Trisection.xwm"));
	ShopBGM		= CSGD_XAudio2::GetInstance()->MusicLoadSong(_T("resource/Shop.xwm"));
	CursorID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/SGD_MenuCursor.png"));
	ShopBmp		= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/shop.png"));
	FontID		= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/LARPFont.png"),D3DCOLOR_XRGB(0,0,0));
	TennisballID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/TennisBall.png"));
	PlungerID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/plunger.png"));
	fireCrackerID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/firecracker.png"));
	WaterBalloonID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/WaterBalloon.png"));
	twentyBMPID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/CJTwenty.png"));

	
	blankRectID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/blankRect.png"),D3DCOLOR_XRGB(0,0,0));
	//tileBmpID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/testtileset.bmp"));
	Font.Initialize(FontID,"LARPFont.fnt");
	RainSound	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/Thunder.wav"));
	SnowSound	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/Snow.wav"));
	Explosion	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Boom.png"));
	declineID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Decline.wav"));
	acceptID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Accept.wav"));
	errorID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_InGame_Error.wav"));
	moveID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/GUI/GUI_Main_Move.wav"));
	sunnyID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Announcer_Sunny.wav"));
	twentyID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Announcer_20.wav"));
	drinkID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/DrinkSoda.wav"));
	inhalerID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Inhaler.wav"));
	reinforceID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/DuctTape.wav"));
	gotchaID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Knight_GotchaBro.wav"));
	hideID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Rogue_CantSeeMe.wav"));
	healID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Heal.wav"));
	chickenID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_Chicken.wav"));
	pansyID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_CmonYouPansy.wav"));
	drawID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_Draw.wav"));
	biteID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_illBiteYourLegsOff.wav"));
	noneID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_NoneShallPass.wav"));
	imID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_ImInvincible.wav"));
	woundID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/BlackKnight_JustAFleshWound.wav"));
	allergyID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Powder_Throw.wav"));
	boltID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_LightningBolt.wav"));
	fireID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Fireball.wav"));
	waterID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Tsunami.wav"));
	boingID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Bow_Boing.wav"));
	thudID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Cardboard_Impact.wav"));
	swingID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Cardboard_Swish.wav"));
	throwID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/Throw_Item.wav"));
	splashID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/WaterBalloon.wav"));
	crackerID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/FireCracker.wav"));
	tennisID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/FX/TennisBall.wav"));
	rhurtID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Rogue_Damage.wav"));
	whurtID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Damage.wav"));
	khurtID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Knight_Damage.wav"));
	ahurtID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Archer_Damage.wav"));
	kdeathID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Knight_Death.wav"));
	rdeathID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Rogue_Death.wav"));
	wdeathID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Wizard_Death.wav"));
	adeathID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/soundFX/Characters/Archer_Death.wav"));
	PanelID	= CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/HUD.png"));
	selectID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/SelectionBox.png"));
	BackgroundID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/optionsmenu.png"));

	//load Dice Images
	DiceImages.push_back(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/DiceSheet.png")));
	DiceImages.push_back(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/CJDiceSheet.bmp")));

	//Battle window stuff
	FadeWindowImg = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/FadeWindow.png"));

	// Set up sound
	CSGD_XAudio2::GetInstance()->SFXSetMasterVolume(Game::GetInstance()->SfxVol);
	CSGD_XAudio2::GetInstance()->MusicSetMasterVolume(Game::GetInstance()->BgmVol);
	CSGD_XAudio2::GetInstance()->MusicSetSongPan(BGMID, Game::GetInstance()->Pan);
	//CSGD_XAudio2::GetInstance()->MusicSetSongPan(ShopBGM, Game::GetInstance()->Pan);
	CSGD_XAudio2::GetInstance()->MusicPlaySong(BGMID, true);

	// Set up AnimationManager 
	myManager = Game::GetInstance()->GetAnimManager();
	
	// Init message system
	MS = MessagingSystem::GetInstance();
	MS->InitMessageSystem(&GamePlayState::MessageProc);

	// init tile manager
	this->gameGrid = TileManager::GetInstance();
	


	


	//ParticleManager
	ParticleManager::GetInstance()->Load("Rain.xml");
	ParticleManager::GetInstance()->Load("Snow.xml");
	ParticleManager::GetInstance()->Load("TsunamiRight.xml");
	ParticleManager::GetInstance()->Load("FireBall.xml");
	ParticleManager::GetInstance()->Load("Allergies.xml");
	AllKeys.push_back("FireBall.xml");
	AllKeys.push_back("Rain.xml");
	AllKeys.push_back("Snow.xml");
	AllKeys.push_back("TsunamiRight.xml");
	AllKeys.push_back("Allergies.xml");


	myManager->LoadAnimations("animations.xml");
	//myManager->LoadAnimations("resource/Selected.xml");
}

bool GamePlayState::Input(void)
{
	ArcadeInput();

	// Pause/Unpause
	if(!Save && !Load && !gameWon && !gameWon2 && !prebattle)
		if((CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE) || arcadeEscape )&& !StatsMenu && !SelectingaTile)
			Paused = !Paused;

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_BACKSPACE)||arcadeBackspace)
	{
		if(!Save && !Load && !gameWon && !gameWon2 && !Paused)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
			//ItemMenu && !Command && !Attack && !Movement && !abilityMenu
			ItemMenu = false;
			Command = false;
			Attack = false;
			Movement = false;
			abilityMenu = false;
			abilitySelection = false;
			abilityTargeting = false;
			
			TileManager::GetInstance()->ResetHighlights();

		}
	}

	// Pause & Save & Load Menu Input
	if(Load && !Paused && !Save && !gameWon && !gameWon2 && !StartGame)
	{
		LoadInput();
	}

	else if(tutStart && !StartGame && !Load && !Paused && !Save && !gameWon && !gameWon2)
	{
		TutorialInput();
	}
	else if(prebattle)
	{
		PrebattleInput();
	}
	else if(StartGame && !Load && !Paused && !Save && !gameWon && !gameWon2)
	{
		
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
		{

			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			StartChoice--;
			if(StartChoice < 0)
				StartChoice = 2;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			StartChoice++;
			if(StartChoice > 2)
				StartChoice = 0;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
		{


			CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
			if(StartChoice == 0)
			{
				

				StartGame = false;
				prebattle = true;
				//cout << "prebattle turned to true";
			}
			else if(StartChoice == 1)
			{
				ShopMenu = true;
				StartGame = false;
			}
			else if(StartChoice == 2)
			{
				mapSelectBool = true;
				StartGame = false;
			}
		}
	}
	else if(ShopMenu && !prebattle && !Load)
	{
		CSGD_XAudio2::GetInstance()->MusicStopSong(BGMID);
		if(!CSGD_XAudio2::GetInstance()->MusicIsSongPlaying(ShopBGM))
		CSGD_XAudio2::GetInstance()->MusicPlaySong(ShopBGM, true);
		
		ShopInput();

	}
	else if(Paused && !Save && !Load)
	{
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			Resume = !Resume;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			Resume = !Resume;
		}

		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
		{
			if(Resume)
				Paused = false;
			else if(!Resume)
			{
				Paused = false;
				Save = true;
			}
		}
	}
	else if(Save && !Paused && !Load)
	{
		SaveInput();
	}
	
	else if(mapSelectBool)
	{
		MapSelectInput();
	}
	else
	{
		if(DiceShown == false && DiceRolled == false)
			GameInput();
	}
	return true;
}

void GamePlayState::Update(float fElapsedTime)
{
	//scaleInc = 0.1f * fElapsedTime;
	// If the game isn't paused, update
	if(actionWindow)
	{
		actionWindowTimer += fElapsedTime;
		if(actionWindowTimer >= 2.0f)
		{
			actionWindow = false;
		}
	}

	if(twentyRender)
	{
		
		if(twentyPosX <= -1)
		{
			twentyPosX += (int)(fElapsedTime*500);			
		}
		else
		{
			twentyRender = false;
		}
			
	}
	else
	{
		if(twentyPosX > -100)
		{
			twentyPosX -= (int)(fElapsedTime*500);
		}
	}

	if(!Paused && !Load && !Save && !prebattle && !StartGame && !SelectingaTile)
	{
		if(playerTurn && !DiceShown && !DiceRolled)
		{
			int numPlayerDone = 0;

			for(unsigned int i = 0; i < this->Characters.size();i++)
			{
				if((Characters[i]->IsDead() || Characters[i]->GetHP() <= 0 ||  Characters[i]->UsedAction()) && Characters[i]->IsPlayer())
					numPlayerDone++;
			}


			if(numPlayerDone == 4)
			{

				playerTurn = !playerTurn;
				Turn = !Turn;
				Timer = 0.0f;
				ShowTurn = true;

				if(!playerTurn)
				{
					ai->SetCurrChar(0);
				}

				for(unsigned int i = 0; i < this->Characters.size();i++)
				{
					this->Characters[i]->SetActed(false);
					this->Characters[i]->SetMoved(false);
					this->Characters[i]->UpdateStatusEffects();
				}

				WeatherTime++;
			}
		}

		if(SelectingaTile == true || prebattle)
		{
		}
		else
		{
			vector<BaseCharacter*>::iterator iter = Characters.begin();
		
			if(mapToUse != -1)
			{
				gameGrid->Update(fElapsedTime);
			}
			if(ShowTurn)
			{
				Timer += fElapsedTime;
				if(Timer >= 2.0f)
				{
					Timer = 0.0f;
					ShowTurn = false;
				}
			}

			if(!playerTurn)
			{
				if(DiceShown == false && DiceRolled == false)
					ai->Update(fElapsedTime);
			}

			for( ; iter != Characters.end(); ++iter)
			{
				(*iter)->Update(fElapsedTime);
			}

		}

			
			
			vector<string>::iterator KeyIter = ActiveKeys.begin();

			for( ; KeyIter != ActiveKeys.end(); KeyIter++)
			{		
				if((*KeyIter) == "FireBall.xml" || (*KeyIter) == "TsunamiRight.xml" || (*KeyIter) == "Allergies.xml")
				{
					if(DiceShown == true && ((*KeyIter) == "FireBall.xml" || (*KeyIter) == "TsunamiRight.xml"))
						ParticleManager::GetInstance()->Update(fElapsedTime, (*KeyIter));
					else if((*KeyIter) == "Allergies.xml")
						ParticleManager::GetInstance()->Update(fElapsedTime, (*KeyIter));
				}
				else
					ParticleManager::GetInstance()->Update(fElapsedTime, (*KeyIter));
			}


			if(GetHealing() > 0)
			{
				healingTimer += fElapsedTime;

				//healingShit = true;

				if(healingTimer >= 5.0f)
				{
					SetHealing(0);
					healingTimer = 0.0f;
					healingShit = false;
				}
			}

			if(WeatherTime == WeatherRand)
			{
				ChoseWeather();
				WeatherRand = rand() % 5 + 2;
				WeatherTime = 0;
			}

			if(DiceRolled == true)
			{
				DiceTime1 += fElapsedTime;
				DShownTime += fElapsedTime;
				Shotspeed2 += fElapsedTime * 100.0f;

				if(DiceTime1 > 3.0f)
				{
					DiceRolled = false;
					DiceTime1 = 0.0f;
					DiceShown = true;
					DShownTime = 0.0f;
					Shotspeed2 = 0.0f;
				}
			}

			if(DiceShown == true)
			{
				DiceTime2 += fElapsedTime;
				Shotspeed += fElapsedTime * 100.0f;

				if(DiceTime2 > 5.0f)
				{
					AtkTypeStorage = -1;
					Shotspeed = 0;
					Modifier = 0.0f;
					DiceTime2 = 0.0f;
					DiceShown = false;
					ARolls.clear();
					DRolls.clear();
					AtkRolls.clear();
					DefRolls.clear();

					vector<string>::iterator iter = ActiveKeys.begin();

					for( ; iter != ActiveKeys.end(); )
					{
						if(iter->find("TsunamiRight.xml") == 0)
						{
							ParticleManager::GetInstance()->ResetParticles((*iter));
							iter = ActiveKeys.erase(iter);
						}
						else if(iter->find("FireBall.xml") == 0)
						{
							ParticleManager::GetInstance()->ResetParticles((*iter));
							iter = ActiveKeys.erase(iter);
						}
						else
							iter++;
					}

					CurDefender->SetHP(CurDefender->GetHP() - TotalDamage);

					CurAttacker->ChangeState(CurAttacker->GetAnimInfo()->currentAnimation + CurAttacker->GetFacing() - 1);
					CurDefender->ChangeState(CurDefender->GetAnimInfo()->currentAnimation + CurDefender->GetFacing() - 3);
					CurAttacker = nullptr;
					CurDefender = nullptr;
					multishotbullshitfix = false;
				}
			}

		MS->ProcessMessages();
		
		if(!DiceRolled && !DiceShown)
		{
			unsigned int size = Characters.size();
			int playersDead = 0;
			int enemiesDead = 0;

			for(unsigned int i = 0; i < size; i++)
			{
				if(Characters[i]->IsPlayer() == false)
				{
					if(Characters[i]->IsDead() == true)
					{
						enemiesDead++;
					}
				}
				else
				{
					if(Characters[i]->IsDead() == true)
						playersDead++;
				}
			}
			if(playersDead >= 4)
			{
				gameLost = true;
			}
			else if(enemiesDead >= 5)
			{
				gameWon = true;
			}
		}

		if(gameWon)
		{
			if(mapToUse == 1)
				map2Unlocked = true;
			
			if(mapToUse == 2)
				map3Unlocked = true;

			gameWonTimer += fElapsedTime;

			if(gameWonTimer >= 1)
			{
				gameWon2 = true;
				gameWon = false;
				gameWonTimer = 0;

				tempAtk = Characters[0]->GetAtk();
				tempStm = Characters[0]->GetSta();
				tempDef = Characters[0]->GetDef();
				tempAgi = Characters[0]->GetAgi();
				tempSpd = Characters[0]->GetSpd();
				tempHP	= Characters[0]->GetHP();
				tempMP	= Characters[0]->GetMP();
				tempLvl = Characters[0]->GetLevel();
			}

		}

		if(gameWon2 || gameLost)
		{
			gameWonTimer += fElapsedTime;
			if(gameWonTimer >= 0)
			{
				for(unsigned int i = 0; i < this->Characters.size();i++)
					Characters[i]->GetTile()->RemoveEffect();
				// Saving our characters
				//SaveGame(activeTile, Characters, 1);

				for(unsigned int i = 0; i < this->Characters.size();i++)
				{
					if(Characters[i]->IsPlayer() && Characters[i] != nullptr)
					{
						selectFrom.push_back(Characters[i]);
						Characters.erase(Characters.begin()+i);
						i--;
					}
					else
					{
						delete Characters[i];
						Characters[i] = nullptr;
					}
				}

				Characters.clear();

				//Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				Save = true;
				//InProgress = false;
				mapSelectBool = false;
				//InProgress = false;
				gameWon = false;
				gameWon2 = false;
			}
		}
	}	
}

void GamePlayState::Render(void)
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	/*RECT r;
	r.top = 200;
	r.left = 200;
	r.bottom = 400;
	r.right = 400;*/

	// To ensure text is on top
	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
	//CSGD_Direct3D::GetInstance()->DrawRect(r,0,0,0);

	/*vector<BaseCharacter*>::iterator iter = Characters.begin();

	for( ; iter != Characters.end(); ++iter)
		{
			(*iter)->Render();
		}*/


	// Draw 
	if(LoadFailed)
		Font.Print("Can't Load: Empty File", 50, 400, 2.0f);

	if(Load)
	{
		LoadRender();
	}
	else if(Save)
	{
		SaveRender();
	}

	else if(tutStart)
	{
		TutorialRender();
		
	}
	else if(prebattle)
	{
		PrebattleRender();
	}
	else if(StartGame)
	{		
		pTM->Draw(BackgroundID,0,-138,0.8f,0.72f);
		
		pTM->Draw(PanelID, 180, 30, 2.6f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 180, 65, 2.6f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		
		pTM->Draw(PanelID, 200, 170, 1.8f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 200, 220, 1.8f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 200, 320, 1.8f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 200, 385, 1.8f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		Font.Print("Preparations", 200, 30, 3.0f);
		Font.Print("Begin Map", 250, 180, 2.0f);
		Font.Print("Visit Shop", 250, 230, 2.0f);
		Font.Print("Back", 250, 280, 2.0f);

		if(StartChoice == 0)
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 205);
		}
		else if(StartChoice == 1)
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 255);
		}
		else if(StartChoice == 2)
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 305);
		}
	}
	else if(ShopMenu)
	{
		ShopRender();
	}
	else if(gameWon)
	{
		Font.Print("YOU WIN!!!", 200, 30, 3.0f);
	}

	else if(false)//gameWon2 || gameLost)
	{
		if(this->gameWonTimer < 30)
		{
			if(gameWon2)
			{
				Font.Print("YOU WIN!!!", 200, 30, 3.0f);
			}
			else if(gameLost)
			{
				Font.Print("You Lose :'(", 200, 30, 3.0f);
			}
		}
		else
		{
			Font.Print("You have gained", 30, 30, 1.0f);
			char buffer[50];
			sprintf_s(buffer, "%d", Characters[0]->GetExp());
			Font.Print(buffer, 230, 30, 1.0f);
			Font.Print("experience this battle!", 255, 30, 1.0f);

			Characters[1]->SetHP(50);

			// Increase the character's stats
			if(Characters[0]->GetExp() > 100)
			Characters[0]->LevelUp();

			if(tempLvl < Characters[0]->GetLevel())
			{
				Font.Print("You have leveled up!", 200, 100, 2.0f);
				Font.Print("Your stats have been upgraded!", 200, 150, 2.0f);

				// Displaying before-increase stats
				Font.Print("HP:", 20, 200, 1.0f);
				sprintf_s(buffer, "%d", tempHP);
				Font.Print(buffer, 120, 200, 1.0f);

				Font.Print("MP:", 20, 230, 1.0f);
				sprintf_s(buffer, "%d", tempMP);
				Font.Print(buffer, 120, 230, 1.0f);

				Font.Print("Attack:", 20, 260, 1.0f);
				sprintf_s(buffer, "%d", tempAtk);
				Font.Print(buffer, 120, 260, 1.0f);

				Font.Print("Defense:", 20, 290, 1.0f);
				sprintf_s(buffer, "%d", tempDef);
				Font.Print(buffer, 120, 290, 1.0f);

				Font.Print("Speed:", 20, 320, 1.0f);
				sprintf_s(buffer, "%d", tempSpd);
				Font.Print(buffer, 120, 320, 1.0f);

				Font.Print("Agility:", 20, 350, 1.0f);
				sprintf_s(buffer, "%d", tempAgi);
				Font.Print(buffer, 120, 350, 1.0f);

				Font.Print("Stamina:", 20, 380, 1.0f);
				sprintf_s(buffer, "%d", tempStm);
				Font.Print(buffer, 120, 380, 1.0f);


				// Displaying post-increase stats

				Font.Print("New HP:", 200, 200, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetHP());
				Font.Print(buffer, 360, 200, 1.0f);
			
				Font.Print("New MP:", 200, 230, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetMP());
				Font.Print(buffer, 360, 230, 1.0f);
			
				Font.Print("New Attack:", 200, 260, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetAtk());
				Font.Print(buffer, 360, 260, 1.0f);
			
				Font.Print("New Defense:", 200, 290, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetDef());
				Font.Print(buffer, 360, 290, 1.0f);
			
				Font.Print("New Speed:", 200, 320, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetSpd());
				Font.Print(buffer, 360, 320, 1.0f);
			
				Font.Print("New Agility:", 200, 350, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetAgi());
				Font.Print(buffer, 360, 350, 1.0f);
			
				Font.Print("New Stamina:", 200, 380, 1.0f);
				sprintf_s(buffer, "%d", Characters[0]->GetSta());
				Font.Print(buffer, 360, 380, 1.0f);

			}
		}
	}
	
	else
	{
		if(StatsMenu)
		{
			char buff[50];

			switch(Viewing->GetType())
				{
				case KNIGHT:
					{
						Font.Print("Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case ARCHER:
					{
						Font.Print("Archer", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case ROGUE:
					{
						Font.Print("Rogue", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case WIZARD:
					{
						Font.Print("Wizard", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7)), 30, 3.0f);
						break;
					}
				case BLACK_KNIGHT:
					{
						Font.Print("Black Knight", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 30, 3.0f);
						break;
					}
				};
				Font.Print("Level: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.3)), 60, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetLevel());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.1)), 60, 2.0f);
				Font.Print("Exp: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.3)), 110, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetLevel());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.1)), 110, 2.0f);
				Font.Print("HP: ", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 160, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetHP());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 160, 2.0f);
				Font.Print("MP:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 210, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetMP());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 210, 2.0f);
				Font.Print("Attack", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 260, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetAtk() + Viewing->GetWpn()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 260, 2.0f);
				Font.Print("Defense:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 310, 2.0f);
				sprintf_s(buff, "%d", (Viewing->GetDef() + Viewing->GetArm()));
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 310, 2.0f);
				Font.Print("Weapon:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 360, 2.0f);
				if(Viewing->GetWpnName())
					Font.Print(Viewing->GetWpnName(), (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 360, 2.0f);
				else
					Font.Print("None", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 360, 2.0f);
				sprintf_s(buff, "+%d",Viewing->GetWpn());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.10)), 360, 2.0f);
				Font.Print("Armor:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 410, 2.0f);
				if(Viewing->GetArmName())
					Font.Print(Viewing->GetArmName(), (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 410, 2.0f);
				else
					Font.Print("None", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 410, 2.0f);
				sprintf_s(buff, "+%d", Viewing->GetArm());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.10)), 410, 2.0f);
				Font.Print("Movement:", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9)), 460, 2.0f);
				sprintf_s(buff, "%d", Viewing->GetMov());
				Font.Print(buff, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.60)), 460, 2.0f);
				Font.Print("Press Enter To Return", 120, 530, 2.0f);

		}
		else if(mapSelectBool)
		{
			MapSelectRender();
		}
		else
		{
			GameRender();
		}
	}

	//inner 90% test

	/*RECT percent90;

	percent90.left = (LONG)(Game::GetInstance()->GetWinWidth() - Game::GetInstance()->GetWinWidth()*0.95);
	percent90.top = (LONG)(Game::GetInstance()->GetWinHeight() - Game::GetInstance()->GetWinHeight()*0.95);
	percent90.right = (LONG)(Game::GetInstance()->GetWinWidth()*0.95);
	percent90.bottom = (LONG)(Game::GetInstance()->GetWinHeight()*0.95);

	CSGD_Direct3D::GetInstance()->DrawLine(percent90.left, percent90.top, percent90.right, percent90.top, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(percent90.left, percent90.top, percent90.left, percent90.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(percent90.right, percent90.top, percent90.right, percent90.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(percent90.left, percent90.bottom, percent90.right, percent90.bottom, 255, 0, 0);*/
}

void GamePlayState::Exit(void)
{
	//CSGD_XAudio2* XA = CSGD_XAudio2::GetInstance();
	CSGD_XAudio2::GetInstance()->MusicStopSong(BGMID);
	CSGD_XAudio2::GetInstance()->SFXStopSound(RainSound);
	CSGD_XAudio2::GetInstance()->SFXStopSound(SnowSound);

	if(MS != nullptr)
	{
		MS->ShutdownMsgSystem();
		MS = nullptr;
	}

	if(WeatherSystem::GetInstance() != nullptr)
	{
		WeatherSystem::GetInstance()->DeleteInstance();
	}

	
	ParticleManager::GetInstance()->SetKeys(AllKeys);
	AllKeys.clear();

	//shutdown particle manager
	ParticleManager::GetInstance()->ShutDown();
	ParticleManager::GetInstance()->DeleteInstance();


	// shutdown tile manager and delete the instance
	gameGrid->DestroyGrid();
	gameGrid->DeleteInstance();

	//shutdown animation manager
	if(myManager != nullptr)
	{
		myManager->ShutdownAnimationManager();
		myManager = nullptr;
	}

	if(this->ai != nullptr)
	{
		ai->DeleteInstance();
		ai = nullptr;
	}

	for(unsigned int i = 0; i < Characters.size(); i++)
	{
		if(Characters[i] != nullptr)
		{
			delete Characters[i];
			Characters[i] = nullptr;
		}
	}

	for(unsigned int i = 0; i < Inventory.size(); i++)
	{
		delete Inventory[i];
	}

	for(unsigned int i = 0; i < enemyInventory.size(); i++)
	{
		delete enemyInventory[i];
	}

	for(unsigned int i = 0; i < selectFrom.size();i++)
	{
		if(selectFrom[i] != nullptr)
		{
			delete selectFrom[i];
			selectFrom[i] = nullptr;
		}
	}

	if(CharactersToTake.size() >= 1)
	{
		for(unsigned int i = 0; i < CharactersToTake.size(); i++)
		{
			if(CharactersToTake[i] != nullptr)
			{
				delete CharactersToTake[i];
				CharactersToTake[i] = nullptr;
			}
		}
	}

	selected.clear();
	selectFrom.clear();
	CharactersToTake.clear();
	Characters.clear();
	Inventory.clear();

	if(moveID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(moveID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(moveID);
		moveID = -1;
	}
	
	if(acceptID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(acceptID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(acceptID);
		acceptID = -1;
	}
	
	if(declineID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(declineID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(declineID);
		declineID = -1;
	}
	
	if(errorID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(errorID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(errorID);
		errorID = -1;
	}

	if(sunnyID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(sunnyID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(sunnyID);
		sunnyID = -1;
	}

	if(twentyID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(twentyID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(twentyID);
		twentyID = -1;
	}

	if(drinkID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(drinkID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(drinkID);
		drinkID = -1;
	}

	if(adeathID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(adeathID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(adeathID);
		adeathID = -1;
	}

	if(rdeathID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(rdeathID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(rdeathID);
		rdeathID = -1;
	}

	if(wdeathID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(wdeathID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(wdeathID);
		wdeathID = -1;
	}

	if(kdeathID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(kdeathID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(kdeathID);
		kdeathID = -1;
	}

	if(inhalerID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(inhalerID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(inhalerID);
		inhalerID = -1;
	}
	
	if(reinforceID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(reinforceID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(reinforceID);
		reinforceID = -1;
	}

	if(gotchaID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(gotchaID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(gotchaID);
		gotchaID = -1;
	}

	if(hideID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(hideID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(hideID);
		hideID = -1;
	}

	if(woundID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(woundID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(woundID);
		woundID = -1;
	}

	if(chickenID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(chickenID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(chickenID);
		chickenID = -1;
	}

	if(pansyID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(pansyID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(pansyID);
		pansyID = -1;
	}

	if(drawID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(drawID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(drawID);
		drawID = -1;
	}

	if(biteID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(biteID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(biteID);
		biteID = -1;
	}

	if(noneID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(noneID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(noneID);
		noneID = -1;
	}

	if(imID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(imID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(imID);
		imID = -1;
	}

	if(woundID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(woundID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(woundID);
		woundID = -1;
	}

	if(allergyID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(allergyID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(allergyID);
		allergyID = -1;
	}

	if(boltID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(boltID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(boltID);
		boltID = -1;
	}

	if(waterID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(waterID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(waterID);
		waterID = -1;
	}

	if(fireID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(fireID);
		fireID = -1;
	}

	if(boingID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(boingID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(boingID);
		boingID = -1;
	}

	if(thudID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(thudID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(thudID);
		thudID = -1;
	}

	if(swingID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(swingID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(swingID);
		swingID = -1;
	}

	if(throwID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(throwID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(throwID);
		throwID = -1;
	}

	if(splashID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(splashID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(splashID);
		splashID = -1;
	}

	if(crackerID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(crackerID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(crackerID);
		crackerID = -1;
	}

	if(tennisID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(tennisID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(tennisID);
		tennisID = -1;
	}

	if(rhurtID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(rhurtID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(rhurtID);
		rhurtID = -1;
	}

	if(whurtID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(whurtID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(whurtID);
		whurtID = -1;
	}

	if(ahurtID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(ahurtID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(ahurtID);
		ahurtID = -1;
	}

	if(khurtID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXStopSound(khurtID);
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(khurtID);
		khurtID = -1;
	}

	if(SnowSound!= -1)
	{
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(SnowSound);
		SnowSound = -1;
	}

	if(RainSound != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(RainSound);
		RainSound = -1;
	}

	if(BGMID != -1)
	{
		CSGD_XAudio2::GetInstance()->MusicUnloadSong(BGMID);
		BGMID = -1;
	}

	if(ShopBGM != -1)
	{
		CSGD_XAudio2::GetInstance()->MusicUnloadSong(ShopBGM);
		ShopBGM = -1;
	}

	if(BackgroundID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(BackgroundID);
		BackgroundID = -1;
	}

	if(selectID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(selectID);
		selectID = -1;
	}

	if(CursorID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(CursorID);
		CursorID = -1;
	}

	if(twentyBMPID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(twentyBMPID);
		twentyBMPID = -1;
	}

	if(ShopBmp != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(ShopBmp);
		ShopBmp = -1;
	}

	if(FontID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FontID);
		FontID = -1;
	}
	if(this->tileBmpID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(tileBmpID);
		tileBmpID = -1;
	}

	if(healID != -1)
	{
		CSGD_XAudio2::GetInstance()->SFXUnloadSound(healID);
		healID = -1;
	}

	if(FadeWindowImg != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FadeWindowImg);
		FadeWindowImg = -1;
	}

	if(Explosion != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(Explosion);
		Explosion = -1;
	}

	if(blankRectID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(blankRectID);
		blankRectID = -1;
	}

	if(TennisballID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(TennisballID);
		TennisballID = -1;
	}
	
	if(PlungerID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(PlungerID);
		PlungerID = -1;
	}
	
	if(fireCrackerID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(fireCrackerID);
		fireCrackerID = -1;
	}
	
	if(WaterBalloonID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(WaterBalloonID);
		WaterBalloonID = -1;
	}

	if(PanelID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(PanelID);
		PanelID = -1;
	}

	cursorMoved = false;
	AImoving = false;

	MS->DeleteInstance();
	DeleteInstance();
}

// STATIC method to handle messages
void GamePlayState::MessageProc(BaseMessage* pMsg)
{
	GamePlayState* GPS = GamePlayState::GetInstance();
	CSGD_XAudio2* XA = CSGD_XAudio2::GetInstance();

	switch(pMsg->GetID())
	{
	case MSG_CHAR_DEATH:
		{
			CharacterDeathMessage* CDM = (CharacterDeathMessage*)pMsg;
			switch(CDM->Type())
			{
			case KNIGHT:
				if(!XA->SFXIsSoundPlaying(GPS->kdeathID))
				XA->SFXPlaySound(GPS->kdeathID);
				break;

			case ARCHER:
				if(!XA->SFXIsSoundPlaying(GPS->adeathID))
				XA->SFXPlaySound(GPS->adeathID);
				break;

			case ROGUE:
				if(!XA->SFXIsSoundPlaying(GPS->rdeathID))
				XA->SFXPlaySound(GPS->rdeathID);
				break;

			case WIZARD:
				if(!XA->SFXIsSoundPlaying(GPS->wdeathID))
				XA->SFXPlaySound(GPS->wdeathID);
				break;

			case BLACK_KNIGHT:
				if(!XA->SFXIsSoundPlaying(GPS->drawID))
				XA->SFXPlaySound(GPS->drawID);
				break;

			};
			

			CDM->Character()->GetAnimInfo()->Dead = true;

			break;
		}
	case MSG_CREATE_CHR:
		{
			CreateCharacterMessage* CCM = (CreateCharacterMessage*)pMsg;
			switch(CCM->GetClass())
			{
			case KNIGHT:
				{
					BaseCharacter* c = new Knight(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;

			case ROGUE:
				{
					BaseCharacter* c = new Rogue(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;

			case WIZARD:
				{
					BaseCharacter* c = new Wizard(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					//c->SetHP(1);
					c->Release();
				}
				break;

			case ARCHER:
				{
					BaseCharacter* c = new Archer(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
					break;
				}

			case BLACK_KNIGHT:
				{
					BaseCharacter* c = new BlackKnight(CCM->IsEnemy());
					c->SetTile(GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY()));
					GPS->Characters.push_back(c);
					GPS->gameGrid->GetTile(CCM->GetTileX(), CCM->GetTileY())->SetCharacter(c);
					c->Release();
				}
				break;
			};
			break;
		}
	
	case MSG_WIN_TILE_EVENT:
		{
			GPS->gameWon = true;
			break;
		}

	case MSG_CREATE_ITEM:
		{
			CreateItemMessage* CIM = (CreateItemMessage*)pMsg;
			Item* i = new Item(CIM->GetItemID());
			GPS->Inventory.push_back(i);
			i = nullptr;
			delete i;
			break;
		}

	case MSG_TAKE_CHAR:
		{
			TakeCharacterMsg* TCM = (TakeCharacterMsg*)pMsg;
			switch(TCM->GetClass())
			{
			case KNIGHT:
				{
				BaseCharacter* Character = new Knight(true);
				GPS->CharactersToTake.push_back(Character);
				GPS->SizeOfParty++;
				Character->Release();
				}
				break;
			case WIZARD:
				{
				BaseCharacter* Character = new Wizard(true);
				GPS->CharactersToTake.push_back(Character);
				GPS->SizeOfParty++;
				Character->Release();
				}
				break;
			case ROGUE:
				{
				BaseCharacter* Character = new Rogue(true);
				GPS->CharactersToTake.push_back(Character);
				GPS->SizeOfParty++;
				Character->Release();
				}
				break;
			case ARCHER:
				{
				BaseCharacter* Character = new Archer(true);
				GPS->CharactersToTake.push_back(Character);
				GPS->SizeOfParty++;
				Character->Release();
				}
				break;
			};
			break;
		}
	};
}

void GamePlayState::SaveGame(Tile * curTile, vector<BaseCharacter*>charList, int fileNumber)
{
	// Create the TinyXML document
	TiXmlDocument doc;

	// Create the TinyXML Declaration (version)
	TiXmlDeclaration* pDec = new TiXmlDeclaration( "1.0", "utf-8", "" );

	// Write the declaration to the document
	doc.LinkEndChild( pDec );

	TiXmlElement* pRoot = new TiXmlElement("savedata");
	doc.LinkEndChild(pRoot);
	pRoot->SetAttribute("InProgress", InProgress);



	TiXmlElement* pChars = new TiXmlElement("characters");
	pRoot->LinkEndChild(pChars);

	vector<BaseCharacter*>::iterator iter = Characters.begin();
	for( ; iter != Characters.end(); ++iter)
	{
		TiXmlElement* pChar = new TiXmlElement("character");
		pChar->SetAttribute("Player", (*iter)->IsPlayer());
		pChar->SetAttribute("Type", (*iter)->GetType());
		pChar->SetAttribute("Level", (*iter)->GetLevel());
		pChar->SetAttribute("HP", (*iter)->GetHP());
		pChar->SetAttribute("MaxHP", (*iter)->GetMaxHP());
		pChar->SetAttribute("MP", (*iter)->GetMP());
		pChar->SetAttribute("MaxMP", (*iter)->GetMaxMP());
		pChar->SetAttribute("Attack", (*iter)->GetAtk());
		pChar->SetAttribute("Defense", (*iter)->GetDef());
		pChar->SetAttribute("Speed", (*iter)->GetSpd());
		pChar->SetAttribute("Agility", (*iter)->GetAgi());
		pChar->SetAttribute("Stamina", (*iter)->GetSta());
		pChar->SetAttribute("Experience", (*iter)->GetExp());
		pChar->SetAttribute("MoveRng", (*iter)->GetMov());
		pChar->SetAttribute("AtkRng", (*iter)->GetRng());
		pChar->SetAttribute("Weapon", (*iter)->GetWpn());
		pChar->SetAttribute("Armor", (*iter)->GetArm());
		pChar->SetAttribute("Moved", (*iter)->HasMoved());
		pChar->SetAttribute("Acted", (*iter)->UsedAction());
		pChar->SetAttribute("TileX", (*iter)->GetTile()->GetX());
		pChar->SetAttribute("TileY", (*iter)->GetTile()->GetY());

		if((*iter)->GetArmName() == nullptr)
			pChar->SetAttribute("ArmorString","None");
		else
			pChar->SetAttribute("ArmorString",(*iter)->GetArmName());

		if((*iter)->GetWpnName() == nullptr)
			pChar->SetAttribute("WeaponString","None");
		else
			pChar->SetAttribute("WeaponString",(*iter)->GetWpnName());

		pChar->SetAttribute("IsDead",(*iter)->IsDead());
		pChar->SetAttribute("FacingDirection",(*iter)->GetFacing());
		
		pChars->LinkEndChild(pChar);
	}

	TiXmlElement* pChars2 = new TiXmlElement("charactersToTake");
	pRoot->LinkEndChild(pChars2);

	iter = CharactersToTake.begin();
	for( ; iter != CharactersToTake.end(); ++iter)
	{
		TiXmlElement* pChar = new TiXmlElement("character");
		pChar->SetAttribute("Player", (*iter)->IsPlayer());
		pChar->SetAttribute("Type", (*iter)->GetType());
		pChar->SetAttribute("Level", (*iter)->GetLevel());
		pChar->SetAttribute("HP", (*iter)->GetHP());
		pChar->SetAttribute("MaxHP", (*iter)->GetMaxHP());
		pChar->SetAttribute("MP", (*iter)->GetMP());
		pChar->SetAttribute("MaxMP", (*iter)->GetMaxMP());
		pChar->SetAttribute("Attack", (*iter)->GetAtk());
		pChar->SetAttribute("Defense", (*iter)->GetDef());
		pChar->SetAttribute("Speed", (*iter)->GetSpd());
		pChar->SetAttribute("Agility", (*iter)->GetAgi());
		pChar->SetAttribute("Stamina", (*iter)->GetSta());
		pChar->SetAttribute("Experience", (*iter)->GetExp());
		pChar->SetAttribute("MoveRng", (*iter)->GetMov());
		pChar->SetAttribute("AtkRng", (*iter)->GetRng());
		pChar->SetAttribute("Weapon", (*iter)->GetWpn());
		pChar->SetAttribute("Armor", (*iter)->GetArm());
		pChar->SetAttribute("Moved", (*iter)->HasMoved());
		pChar->SetAttribute("Acted", (*iter)->UsedAction());

		
		if((*iter)->GetArmName() == nullptr)
			pChar->SetAttribute("ArmorString","None");
		else
			pChar->SetAttribute("ArmorString",(*iter)->GetArmName());

		if((*iter)->GetWpnName() == nullptr)
			pChar->SetAttribute("WeaponString","None");
		else
			pChar->SetAttribute("WeaponString",(*iter)->GetWpnName());

		pChar->SetAttribute("IsDead",(*iter)->IsDead());
		pChar->SetAttribute("FacingDirection",(*iter)->GetFacing());
		
		pChars2->LinkEndChild(pChar);
	}

	TiXmlElement* pChars3 = new TiXmlElement("characterInventory");
	pRoot->LinkEndChild(pChars3);

	iter = selectFrom.begin();
	for( ; iter != selectFrom.end(); ++iter)
	{
		TiXmlElement* pChar = new TiXmlElement("character");
		pChar->SetAttribute("Player", (*iter)->IsPlayer());
		pChar->SetAttribute("Type", (*iter)->GetType());
		pChar->SetAttribute("Level", (*iter)->GetLevel());
		pChar->SetAttribute("HP", (*iter)->GetHP());
		pChar->SetAttribute("MaxHP", (*iter)->GetMaxHP());
		pChar->SetAttribute("MP", (*iter)->GetMP());
		pChar->SetAttribute("MaxMP", (*iter)->GetMaxMP());
		pChar->SetAttribute("Attack", (*iter)->GetAtk());
		pChar->SetAttribute("Defense", (*iter)->GetDef());
		pChar->SetAttribute("Speed", (*iter)->GetSpd());
		pChar->SetAttribute("Agility", (*iter)->GetAgi());
		pChar->SetAttribute("Stamina", (*iter)->GetSta());
		pChar->SetAttribute("Experience", (*iter)->GetExp());
		pChar->SetAttribute("MoveRng", (*iter)->GetMov());
		pChar->SetAttribute("AtkRng", (*iter)->GetRng());
		pChar->SetAttribute("Weapon", (*iter)->GetWpn());
		pChar->SetAttribute("Armor", (*iter)->GetArm());
		pChar->SetAttribute("Moved", (*iter)->HasMoved());
		pChar->SetAttribute("Acted", (*iter)->UsedAction());

		
		if((*iter)->GetArmName() == nullptr)
			pChar->SetAttribute("ArmorString","None");
		else
			pChar->SetAttribute("ArmorString",(*iter)->GetArmName());

		if((*iter)->GetWpnName() == nullptr)
			pChar->SetAttribute("WeaponString","None");
		else
			pChar->SetAttribute("WeaponString",(*iter)->GetWpnName());

		pChar->SetAttribute("IsDead",(*iter)->IsDead());
		pChar->SetAttribute("FacingDirection",(*iter)->GetFacing());
		
		pChars3->LinkEndChild(pChar);
	}

	TiXmlElement* pInv = new TiXmlElement("inventory");
	pRoot->LinkEndChild(pInv);

	vector<Item*>::iterator iter2 = Inventory.begin();
	for( ; iter2 != Inventory.end(); ++iter2)
	{
		TiXmlElement* pItem = new TiXmlElement("item");
		pItem->SetAttribute("Type", (*iter2)->GetID());
		pInv->LinkEndChild(pItem);
	}

	TiXmlElement* pInv2 = new TiXmlElement("enemyInventory");
	pRoot->LinkEndChild(pInv2);

	iter2 = this->enemyInventory.begin();
	for( ; iter2 != enemyInventory.end(); ++iter2)
	{
		TiXmlElement* pItem = new TiXmlElement("item");
		pItem->SetAttribute("Type", (*iter2)->GetID());
		pInv->LinkEndChild(pItem);
	}

	TiXmlElement* mapInfo = new TiXmlElement("map");
	pRoot->LinkEndChild(mapInfo);

	mapInfo->SetAttribute("MapID",this->mapToUse);
	mapInfo->SetAttribute("Weather",this->WeatherType);
	mapInfo->SetAttribute("PlayerTurn",this->playerTurn);
	mapInfo->SetAttribute("SelectingATile",this->SelectingaTile);
	mapInfo->SetAttribute("SelectingCount",this->SelectingCount);

	TiXmlElement* playerInfo = new TiXmlElement("player");
	pRoot->LinkEndChild(playerInfo);

	playerInfo->SetAttribute("Gold",Gold);
	playerInfo->SetAttribute("SizeOfParty",SizeOfParty);
	playerInfo->SetAttribute("Map2Unlocked",map2Unlocked);
	playerInfo->SetAttribute("Map3Unlocked",map3Unlocked);

	// Save the XML Document to the correct "slot"
	switch(fileNumber)
	{
	case 1:
		{
			const char* name = "SaveSlot1.xml";
			doc.SaveFile(name);
			break;
		}

	case 2:
		{
			const char* name = "SaveSlot2.xml";
			doc.SaveFile(name);
			break;
		}

	case 3:
		{
			const char* name = "SaveSlot3.xml";
			doc.SaveFile(name);
			break;
		}
	};
}

bool GamePlayState::LoadSave(int fileNumber)
{

	for(unsigned int i = 0; i < Characters.size(); i++)
	{
		if(Characters[i] != nullptr)
		{
			delete Characters[i];
			Characters[i] = nullptr;
		}
	}

	for(unsigned int i = 0; i < Inventory.size(); i++)
	{
		delete Inventory[i];
	}

	for(unsigned int i = 0; i < enemyInventory.size(); i++)
	{
		delete enemyInventory[i];
	}

	for(unsigned int i = 0; i < selectFrom.size();i++)
	{
		if(selectFrom[i] != nullptr)
		{
			delete selectFrom[i];
			selectFrom[i] = nullptr;
		}
	}

	for(unsigned int i = 0; i < selectFrom.size();i++)
	{
		if(selected[i] != nullptr)
		{
			delete selected[i];
			selected[i] = nullptr;
		}
	}

	gameGrid->DestroyGrid();

	// Create the TinyXML Document
	TiXmlDocument doc;

	int type;
	bool player;
	int level;
	int exp;
	int HP;
	int MaxHP;
	int MP;
	int MaxMP;
	int attack;
	int defense;
	int speed;
	int agility;
	int moveRange;
	int range;
	int stamina;
	int weapon;
	int armor;
	int isPlayer;
	int moved;
	int acted;
	int tileX;
	int tileY;
	int item;

	switch(fileNumber)
	{
	case 1:
		if(doc.LoadFile("SaveSlot1.xml") == false)
			return false;
		break;

	case 2:
		if(doc.LoadFile("SaveSlot2.xml") == false)
			return false;
		break;

	case 3:
		if(doc.LoadFile("SaveSlot3.xml") == false)
			return false;
		break;

	};

	TiXmlElement* pRoot = doc.RootElement();
	if(pRoot == nullptr)
		return false;

	TiXmlElement* map = pRoot->FirstChildElement("map");

	map->Attribute("MapID",&mapToUse);
	map->Attribute("Weather",&WeatherType);
	map->Attribute("PlayerTurn",(int*)(&playerTurn));
	map->Attribute("SelectingATile",(int*)(&SelectingaTile));
	map->Attribute("SelectingCount",&SelectingCount);

	TiXmlElement* playerInfo = pRoot->FirstChildElement("player");

	playerInfo->Attribute("Gold",&Gold);
	playerInfo->Attribute("SizeOfParty",&SizeOfParty);
	playerInfo->Attribute("Map2Unlocked",(int*)(&map2Unlocked));
	playerInfo->Attribute("Map3Unlocked",(int*)(&map3Unlocked));
	pRoot->Attribute("InProgress",(int*)(&InProgress));
	
	if(InProgress)
	{
		switch(mapToUse)
		{
		case 0:
			{
				gameGrid->CreateGrid("ForestMap.xml");
				size_t size;
				TCHAR buffer[128] = {};
				mbstowcs_s(&size,buffer,128,(gameGrid->GetTileSetFile()),128);

				tileBmpID = CSGD_TextureManager::GetInstance()->LoadTexture(buffer);
				gameGrid->SetTileBmpID(this->tileBmpID);
				break;
			}
		case 1:
			{
				gameGrid->CreateGrid("IndoorMap.xml");
				size_t size;
				TCHAR buffer[128] = {};
				mbstowcs_s(&size,buffer,128,(gameGrid->GetTileSetFile()),128);

				tileBmpID = CSGD_TextureManager::GetInstance()->LoadTexture(buffer);
				gameGrid->SetTileBmpID(this->tileBmpID);
				break;
			}
		case 2:
			{
				gameGrid->CreateGrid("LavaMap.xml");
				size_t size;
				TCHAR buffer[128] = {};
				mbstowcs_s(&size,buffer,128,(gameGrid->GetTileSetFile()),128);

				tileBmpID = CSGD_TextureManager::GetInstance()->LoadTexture(buffer);
				gameGrid->SetTileBmpID(this->tileBmpID);
				break;
			}
		};

	}
	else
	{
		this->mapSelectBool = true;
	}


	TiXmlElement* pChars = pRoot->FirstChildElement("characters");

	if(InProgress)
	{
		if(pChars != nullptr)
		{
			TiXmlElement* pChar = pChars->FirstChildElement("character");
			if(pChar != nullptr)
			{
				while(pChar != nullptr)
				{
					BaseCharacter* c;

					if(pChar->Attribute("Player", &isPlayer) != nullptr)
					{
						if(isPlayer == 1)
							player = true;
						else
							player = false;

						//c->SetPlayer(player);
					}

					if(pChar->Attribute("Type", &type) != nullptr)
					{
						switch(type)
						{
						case ARCHER:
							{
								c = new Archer(player);
								break;
							}

						case KNIGHT:
							{
								c = new Knight(player);
								break;
							}

						case ROGUE:
							{
								c = new Rogue(player);
								break;
							}

						case WIZARD:
							{
								c = new Wizard(player);
								break;
							}

						case BLACK_KNIGHT:
							{
								c = new BlackKnight(player);
								break;
							}
						};
					}

					if(pChar->Attribute("Level", &level) != nullptr)
					{
						c->SetLevel((unsigned int)level);
					}

					if(pChar->Attribute("HP", &HP) != nullptr)
						c->SetHP(HP);

					if(pChar->Attribute("MaxHP", &MaxHP) != nullptr)
						c->SetMaxHP(MaxHP);

					if(pChar->Attribute("MP", &MP) != nullptr)
						c->SetMP(MP);

					if(pChar->Attribute("MaxMP", &MaxMP) != nullptr)
						c->SetMaxMP(MaxMP);

					if(pChar->Attribute("Attack", &attack) != nullptr)
						c->SetAtk(attack);

					if(pChar->Attribute("Defense", &defense) != nullptr)
						c->SetDef(defense);

					if(pChar->Attribute("Speed", &speed) != nullptr)
						c->SetSpd(speed);

					if(pChar->Attribute("Agility", &agility) != nullptr)
						c->SetAgi(agility);

					if(pChar->Attribute("Stamina", &stamina) != nullptr)
						c->SetSta(stamina);

					if(pChar->Attribute("Experience", &exp) != nullptr)
						c->SetExp(exp);

					if(pChar->Attribute("MoveRng", &moveRange) != nullptr)
						c->SetMov(moveRange);

					if(pChar->Attribute("AtkRng", &range) != nullptr)
						c->SetRng(range);

					if(pChar->Attribute("Weapon", &weapon) != nullptr)
						c->SetWpn(weapon);

					if(pChar->Attribute("Armor", &armor) != nullptr)
						c->SetArm(armor);

					if(pChar->Attribute("Moved", &moved) != nullptr)
					{
						bool Moved;
						if(moved == 1)
							Moved = true;
						else
							Moved = false;
						c->SetMoved(Moved);
					}

					if(pChar->Attribute("Acted", &acted) != nullptr)
					{
						bool Acted;
						if(acted == 1)
							Acted = true;
						else
							Acted = false;
						c->SetActed(Acted);
					}


					if(pChar->Attribute("TileX", &tileX) == nullptr)
						return false;

					if(pChar->Attribute("TileY", &tileY) == nullptr)
						return false;

				
				

					int temp;

					pChar->Attribute("IsDead",&temp);

					if(temp == 1)
						c->SetDead(true);
					else
						c->SetDead(false);

					pChar->Attribute("FacingDirection",&temp);

					c->SetFacing(temp);


					c->SetTile(gameGrid->GetTile(tileX, tileY));
					gameGrid->GetTile(tileX, tileY)->SetCharacter(c);

					Characters.push_back(c);

					if(pChar->NextSiblingElement() != nullptr)
						pChar = pChar->NextSiblingElement("character");
					else
						break;
				}
			
			}
		}

	}
	pChars = pRoot->FirstChildElement("charactersToTake");
	if(pChars != nullptr)
	{
		TiXmlElement* pChar = pChars->FirstChildElement("character");
		if(pChar != nullptr)
		{
			while(pChar != nullptr)
			{
				BaseCharacter* c;

				if(pChar->Attribute("Player", &isPlayer) != nullptr)
				{
					if(isPlayer == 1)
						player = true;
					else
						player = false;
				}

				if(pChar->Attribute("Type", &type) != nullptr)
				{
					switch(type)
					{
					case ARCHER:
						{
							c = new Archer(player);
							break;
						}

					case KNIGHT:
						{
							c = new Knight(player);
							break;
						}

					case ROGUE:
						{
							c = new Rogue(player);
							break;
						}

					case WIZARD:
						{
							c = new Wizard(player);
							break;
						}

					case BLACK_KNIGHT:
						{
							c = new BlackKnight(player);
							break;
						}
					};
				}

				if(pChar->Attribute("Level", &level) != nullptr)
				{
					c->SetLevel((unsigned int)level);
				}

				if(pChar->Attribute("HP", &HP) != nullptr)
					c->SetHP(HP);

				if(pChar->Attribute("MaxHP", &MaxHP) != nullptr)
					c->SetMaxHP(MaxHP);

				if(pChar->Attribute("MP", &MP) != nullptr)
					c->SetMP(MP);

				if(pChar->Attribute("MaxMP", &MaxMP) != nullptr)
					c->SetMaxMP(MaxMP);

				if(pChar->Attribute("Attack", &attack) != nullptr)
					c->SetAtk(attack);

				if(pChar->Attribute("Defense", &defense) != nullptr)
					c->SetDef(defense);

				if(pChar->Attribute("Speed", &speed) != nullptr)
					c->SetSpd(speed);

				if(pChar->Attribute("Agility", &agility) != nullptr)
					c->SetAgi(agility);

				if(pChar->Attribute("Stamina", &stamina) != nullptr)
					c->SetSta(stamina);

				if(pChar->Attribute("Experience", &exp) != nullptr)
					c->SetExp(exp);

				if(pChar->Attribute("MoveRng", &moveRange) != nullptr)
					c->SetMov(moveRange);

				if(pChar->Attribute("AtkRng", &range) != nullptr)
					c->SetRng(range);

				if(pChar->Attribute("Weapon", &weapon) != nullptr)
					c->SetWpn(weapon);

				if(pChar->Attribute("Armor", &armor) != nullptr)
					c->SetArm(armor);

				if(pChar->Attribute("Moved", &moved) != nullptr)
				{
					bool Moved;
					if(moved == 1)
						Moved = true;
					else
						Moved = false;
					c->SetMoved(Moved);
				}

				if(pChar->Attribute("Acted", &acted) != nullptr)
				{
					bool Acted;
					if(acted == 1)
						Acted = true;
					else
						Acted = false;
					c->SetActed(Acted);
				}

				

				int temp;

				pChar->Attribute("IsDead",&temp);

				if(temp == 1)
					c->SetDead(true);
				else
					c->SetDead(false);

				pChar->Attribute("FacingDirection",&temp);

				c->SetFacing(temp);

				CharactersToTake.push_back(c);

				if(pChar->NextSiblingElement() != nullptr)
					pChar = pChar->NextSiblingElement("character");
				else
					break;
			}
			
		}
	}

	pChars = pRoot->FirstChildElement("characterInventory");
	if(pChars != nullptr)
	{
		TiXmlElement* pChar = pChars->FirstChildElement("character");
		if(pChar != nullptr)
		{
			while(pChar != nullptr)
			{
				BaseCharacter* c;

				if(pChar->Attribute("Player", &isPlayer) != nullptr)
				{
					if(isPlayer == 1)
						player = true;
					else
						player = false;
				}

				if(pChar->Attribute("Type", &type) != nullptr)
				{
					switch(type)
					{
					case ARCHER:
						{
							c = new Archer(player);
							break;
						}

					case KNIGHT:
						{
							c = new Knight(player);
							break;
						}

					case ROGUE:
						{
							c = new Rogue(player);
							break;
						}

					case WIZARD:
						{
							c = new Wizard(player);
							break;
						}

					case BLACK_KNIGHT:
						{
							c = new BlackKnight(player);
							break;
						}
					};
				}

				if(pChar->Attribute("Level", &level) != nullptr)
				{
					c->SetLevel((unsigned int)level);
				}

				if(pChar->Attribute("HP", &HP) != nullptr)
					c->SetHP(HP);

				if(pChar->Attribute("MaxHP", &MaxHP) != nullptr)
					c->SetMaxHP(MaxHP);

				if(pChar->Attribute("MP", &MP) != nullptr)
					c->SetMP(MP);

				if(pChar->Attribute("MaxMP", &MaxMP) != nullptr)
					c->SetMaxMP(MaxMP);

				if(pChar->Attribute("Attack", &attack) != nullptr)
					c->SetAtk(attack);

				if(pChar->Attribute("Defense", &defense) != nullptr)
					c->SetDef(defense);

				if(pChar->Attribute("Speed", &speed) != nullptr)
					c->SetSpd(speed);

				if(pChar->Attribute("Agility", &agility) != nullptr)
					c->SetAgi(agility);

				if(pChar->Attribute("Stamina", &stamina) != nullptr)
					c->SetSta(stamina);

				if(pChar->Attribute("Experience", &exp) != nullptr)
					c->SetExp(exp);

				if(pChar->Attribute("MoveRng", &moveRange) != nullptr)
					c->SetMov(moveRange);

				if(pChar->Attribute("AtkRng", &range) != nullptr)
					c->SetRng(range);

				if(pChar->Attribute("Weapon", &weapon) != nullptr)
					c->SetWpn(weapon);

				if(pChar->Attribute("Armor", &armor) != nullptr)
					c->SetArm(armor);

				if(pChar->Attribute("Moved", &moved) != nullptr)
				{
					bool Moved;
					if(moved == 1)
						Moved = true;
					else
						Moved = false;
					c->SetMoved(Moved);
				}

				if(pChar->Attribute("Acted", &acted) != nullptr)
				{
					bool Acted;
					if(acted == 1)
						Acted = true;
					else
						Acted = false;
					c->SetActed(Acted);
				}

				

				int temp;

				pChar->Attribute("IsDead",&temp);

				if(temp == 1)
					c->SetDead(true);
				else
					c->SetDead(false);

				pChar->Attribute("FacingDirection",&temp);

				c->SetFacing(temp);

				selectFrom.push_back(c);

				if(pChar->NextSiblingElement() != nullptr)
					pChar = pChar->NextSiblingElement("character");
				else
					break;
			}
			
		}
	}

	TiXmlElement* pInv = pRoot->FirstChildElement("inventory");
	if(pInv != nullptr)
	{
		TiXmlElement* pItem = pInv->FirstChildElement("item");
		if(pItem != nullptr)
		{
			while(pItem != nullptr)
			{
				if(pItem->Attribute("Type", &item) != nullptr)
				{
					Item * i = new Item(item);
					switch(item)
					{
					case HPOTION:
						{
							Inventory.push_back(i);
							HPotions += 1;
							break;
						}

					case MPOTION:
						{
							Inventory.push_back(i);
							MPotions += 1;
							break;
						}

					case INHALER:
						{
							Inventory.push_back(i);
							Inhalers += 1;
							break;
						}
					case KN_ARM:
						{
							i->SetName("Boxite Armor");
							i->SetVal(4);
							Inventory.push_back(i);
							break;
						}
					case KN_WPN:
						{
							i->SetName("Foam Sword");
							i->SetVal(4);
							Inventory.push_back(i);
							break;
						}
					case WIZ_WPN:
						{
							i->SetName("Flimsy Staff");
							i->SetVal(4);
							Inventory.push_back(i);
							break;
						}
					case WIZ_ARM:
						{
							i->SetName("Old Bathrobe");
							i->SetVal(2);
							Inventory.push_back(i);
							break;
						}
					case ARCH_WPN:
						{
							i->SetName("Toy Bow");
							i->SetVal(2);
							Inventory.push_back(i);
							break;
						}
					case ARCH_ARM:
						{
							i->SetName("Tight Tights");
							i->SetVal(2);
							Inventory.push_back(i);
							break;
						}
					case RG_WPN:
						{
							i->SetName("Plastic Daggers");
							i->SetVal(2);
							Inventory.push_back(i);
							break;
						}
					case RG_ARM:
						{
							i->SetName("Worn Pajamas");
							i->SetVal(2);
							Inventory.push_back(i);
							break;
						}
					};
				}

				if(pItem->NextSiblingElement() != nullptr)
					pItem = pItem->NextSiblingElement("item");
				else
					break;
			}
		}
	}

	pInv = pRoot->FirstChildElement("enemyInventory");
	if(pInv != nullptr)
	{
		TiXmlElement* pItem = pInv->FirstChildElement("item");
		if(pItem != nullptr)
		{
			while(pItem != nullptr)
			{
				if(pItem->Attribute("Type", &item) != nullptr)
				{
					Item * i = new Item(item);
					switch(item)
					{
					case HPOTION:
						{
							enemyInventory.push_back(i);
							//HPotions += 1;
							break;
						}

					case MPOTION:
						{
							enemyInventory.push_back(i);
							//MPotions += 1;
							break;
						}

					case INHALER:
						{
							enemyInventory.push_back(i);
							//Inhalers += 1;
							break;
						}
					
					};
				}

				if(pItem->NextSiblingElement() != nullptr)
					pItem = pItem->NextSiblingElement("item");
				else
					break;
			}
		}
	}

	int tempI;
	pRoot->Attribute("InProgress",&tempI);
	if(tempI == 1)
	{
		this->InProgress = true;
	}
	else
	{
		this->InProgress = false;
	}

	LoadEquipment();

	return true;
}

int GamePlayState::DiceRoll(BaseCharacter* Attacker, BaseCharacter* Defender, int wizardEnum)
{
	CurAttacker = Attacker;
	CurDefender = Defender;

	if(AtkTypeStorage != MULTI_SHOT)
	{
		CurAttacker->ChangeState(CurAttacker->GetAnimInfo()->currentAnimation - CurAttacker->GetFacing() + 1);
		CurDefender->ChangeState(CurDefender->GetAnimInfo()->currentAnimation - CurDefender->GetFacing() + 3);
	}
	else
	{
		if(multishotbullshitfix == false)
		{
			CurAttacker->ChangeState(CurAttacker->GetAnimInfo()->currentAnimation - CurAttacker->GetFacing() + 1);
			CurDefender->ChangeState(CurDefender->GetAnimInfo()->currentAnimation - CurDefender->GetFacing() + 3);
			multishotbullshitfix = true;
		}
	}

	int NumRolls = 0;
	int curAttk = Attacker->GetAtk() + Attacker->GetWpn();

	if(wizardEnum != -1)
	{
		switch(wizardEnum)
		{
		case LIGHTNING_BOLT:
			{
				curAttk = (4 * Attacker->GetLevel()) + 8;
				AtkTypeStorage = LIGHTNING_BOLT;
				break;
			}
		case FIRE_BALLS:
			{
				curAttk = (6 * Attacker->GetLevel()) + 12;
				break;
			}
		case TSUNAMI:
			{
				curAttk = (8 * (Attacker->GetLevel()-1)) + 34;
				break;
			}
		};
	}

	int curDef = Defender->GetDef() + Defender->GetArm();
	vector<int> DiceRolls;
	int i = 0;

	if(curAttk >= 20)
	{
		NumRolls = (curAttk / 20);
		curAttk -= NumRolls*20;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(20);
		}
	}
	if(curAttk >= 12)
	{
		NumRolls =  (curAttk / 12);
		curAttk -= NumRolls*12;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(12);
		}
	}
	if(curAttk >= 10)
	{
		NumRolls =  (curAttk / 10);
		curAttk -= NumRolls*10;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(10);
		}
	}
	if(curAttk >= 8)
	{
		NumRolls =  (curAttk / 8);
		curAttk -= NumRolls*8;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(8);
		}
	}
	if(curAttk >= 6)
	{
		NumRolls =  (curAttk / 6);
		curAttk -= NumRolls*6;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(6);
		}
	}
	if(curAttk >= 4)
	{
		NumRolls = (curAttk / 4);
		curAttk -= NumRolls*4;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(4);
		}
	}
	
	int X = DiceRolls.size();
	int damage = 0;
	int Roll = 0;

	for(i = 0; i < X; i++)
	{
		AtkRolls.push_back(DiceRolls[i]);
		Roll = rand() % DiceRolls[i] + 1;
		ARolls.push_back(Roll);
		damage += Roll;
	}

	DiceRolls.clear();

	if(curDef >= 20)
	{
		NumRolls = (curDef / 20);
		curDef -= NumRolls*20;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(20);
		}
	}
	if(curDef >= 12)
	{
		NumRolls =  (curDef / 12);
		curDef -= NumRolls*12;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(12);
		}
	}
	if(curDef >= 10)
	{
		NumRolls =  (curDef / 10);
		curDef -= NumRolls*10;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(10);
		}
	}
	if(curDef >= 8)
	{
		NumRolls =  (curDef / 8);
		curDef -= NumRolls*8;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(8);
		}
	}
	if(curDef >= 6)
	{
		NumRolls =  (curDef / 6);
		curDef -= NumRolls*6;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(6);
		}
	}
	if(curDef >= 4)
	{
		NumRolls = (curDef / 4);
		curDef -= NumRolls*4;

		for(i = 0; i < NumRolls; i++)
		{
			DiceRolls.push_back(4);
		}
	}

	X = DiceRolls.size();
	int Defense = 0;

	for(i = 0; i < X; i++)
	{
		DefRolls.push_back(DiceRolls[i]);
		Roll = rand() % DiceRolls[i] + 1;
		DRolls.push_back(Roll);
		Defense += Roll;
	}

	damage = damage - Defense;
	if(damage <= 0)
		damage = 1;


	DiceRolled = true;

	return damage;
}

void GamePlayState::RenderDice()
{
	BattleWindowFade();

	/*RECT BRECT = {Game::GetInstance()->GetWinWidth()/2 - 350, Game::GetInstance()->GetWinHeight()/2 - 250, Game::GetInstance()->GetWinWidth()/2 + 350, Game::GetInstance()->GetWinHeight()/2 + 250 };  

	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.right, BRECT.top, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.left, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.right, BRECT.top, BRECT.right, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.bottom, BRECT.right, BRECT.bottom, 255, 0, 0);
*/
	BattleWindow();

	int size = DiceImages.size();
	int random = 0;
	int randX = 0;
	int randY = 0;
	int i = 0;
	RECT rect = diceRECT;


	random = rand() % size;
	randX = rand() % (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
	randY = rand() % (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);

	if(DShownTime >= 0.125f)
	{
		diceRECT = DiceCell(randX, randY);

		while(rect.left == diceRECT.left && rect.right == diceRECT.right && rect.top == diceRECT.top && rect.bottom == diceRECT.bottom)
		{
			randX = rand() % (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			randY = rand() % (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			diceRECT = DiceCell(randX, randY);
		}

		DShownTime = 0.0f;
	}

	CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 200, 100, 1.0f, 1.0f, &diceRECT,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

	CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 550, 100, 1.0f, 1.0f, &diceRECT,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
	
}
void GamePlayState::RenderRoll()
{
	BattleWindowFade();

	/*RECT BRECT = {Game::GetInstance()->GetWinWidth()/2 - 350, Game::GetInstance()->GetWinHeight()/2 - 250, Game::GetInstance()->GetWinWidth()/2 + 350, Game::GetInstance()->GetWinHeight()/2 + 250 };  

	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.right, BRECT.top, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.top, BRECT.left, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.right, BRECT.top, BRECT.right, BRECT.bottom, 255, 0, 0);
	CSGD_Direct3D::GetInstance()->DrawLine(BRECT.left, BRECT.bottom, BRECT.right, BRECT.bottom, 255, 0, 0);*/

	BattleWindow();

	int atkX = 0;
	int atkY = 0;
	int atkImage =  -1;
	RECT atkrect = {0, 0, 0, 0};

	int DefX = 0;
	int DefY = 0;
	int DefImage = -1;
	RECT Defrect = {0, 0, 0, 0};

	int Asize = AtkRolls.size();
	int Dsize = DefRolls.size();

	for(int i = 0; i < Asize; i++)
	{
		if(AtkRolls[i] == 4)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 6)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 8)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 125);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 63);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 10)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 12)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 0;
		}
		else if(AtkRolls[i] == 20)
		{
			atkX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			atkY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			atkImage = 1;
		}

		//attack roll
		if(ARolls[i] < atkX)
		{
			atkX = 0;
		}
		else
		{
			if(ARolls[i] % atkX == 0)
			{
				atkX = 1;
			}
			else
				atkX = 0;
		}

		if(ARolls[i] % 2 == 0)
		{
			atkY = (ARolls[i] / 2) - 1;
		}
		else
			atkY = ARolls[i] / 2;


		atkrect = DiceCell(atkX, atkY);


		if(Modifier != 0.0f)
		{
			CSGD_TextureManager::GetInstance()->Draw(Explosion, 160, 40, 1.6f, 0.8f, nullptr, 0.0f, 0.0f,
											 0.0f, D3DCOLOR_ARGB(150, 255, 255, 255));

			char buff[50];
			sprintf_s(buff, "%.2f", Modifier);

			Font.Print("x", 180, 50, 0.8f);
			Font.Print(buff, 200, 50, 1.0f);
		}

		if(Asize == 1)
		{
			CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 200, 100, 1.0f, 1.0f, &atkrect,
			0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

			if(ARolls[i] == 20 && !CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(twentyID) && playVoice)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(twentyID);
				twentyRender = true;
			}
		}
		else if(Asize >= 2 && Asize <= 3)
		{
			CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 100 + (i*64), 100, 1.0f, 1.0f, &atkrect,
			0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

			if(ARolls[i] == 20 && !CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(twentyID) && playVoice)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(twentyID);
				twentyRender = true;
			}
		}
		else if(Asize >= 4)
		{
			if( i <= 2)
				CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 70 + (i*64), 100, 1.0f, 1.0f, &atkrect,
					0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
			else
				CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 70 + ((i-3)*64), 164, 1.0f, 1.0f, &atkrect,
					0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

			if(ARolls[i] == 20 && !CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(twentyID) && playVoice)
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(twentyID);
				twentyRender = true;
			}
		}
	}

	for(int i = 0; i < Dsize; i++)
	{
		if(DefRolls[i] == 4)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 6)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 8)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 125);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 63);
			DefImage = 0;
		}
		else if(DefRolls[i] == 10)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 12)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 0;
		}
		else if(DefRolls[i] == 20)
		{
			DefX = (CSGD_TextureManager::GetInstance()->GetTextureWidth(DiceImages[1]) / 64);
			DefY = (CSGD_TextureManager::GetInstance()->GetTextureHeight(DiceImages[1]) / 51);
			DefImage = 1;
		}

		//Defense roll
		if(DRolls[i] < DefX)
		{
			DefX = 0;
		}
		else
		{
			if(DRolls[i] % DefX == 0)
			{
				DefX = 1;
			}
			else
				DefX = 0;
		}

		if(DRolls[i] % 2 == 0)
		{
			DefY = (DRolls[i] / 2) - 1;
		}
		else
			DefY = DRolls[i] / 2;

		Defrect = DiceCell(DefX, DefY);


		if(Dsize == 1)
			CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 550, 100, 1.0f, 1.0f, &Defrect,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
		else if(Dsize >= 2 && Dsize <= 3)
			CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 500 + (i*64), 100, 1.0f, 1.0f, &Defrect,
				0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
		else if(Dsize >= 4)
		{
			if( i <= 2)
				CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 500 + (i*64), 100, 1.0f, 1.0f, &Defrect,
					0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
			else
				CSGD_TextureManager::GetInstance()->Draw(DiceImages[1], 500 + ((i-3)*64), 164, 1.0f, 1.0f, &Defrect,
					0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
		}
	}

	if(GetDamage() <= 1)
	{
		SetDamage(1);
	}

	CSGD_TextureManager::GetInstance()->Draw(Explosion, Game::GetInstance()->GetWinWidth()/2 - 60, 70, 2.2f, 2.2f, nullptr, 0.0f, 0.0f,
											 0.0f, D3DCOLOR_ARGB(200, 255, 255, 255));

	char buffer[50];
	sprintf_s(buffer, "%d", GetDamage());

	if(GetDamage() >= 10)	
		Font.Print(buffer, Game::GetInstance()->GetWinWidth()/2 - 20, 100, 3.0f);
	else
		Font.Print(buffer, Game::GetInstance()->GetWinWidth()/2 - 5, 100, 3.0f);

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
}

RECT GamePlayState::DiceCell(int X, int Y)
{
	RECT DiceRECT = {0, 0, 0, 0};

	DiceRECT.left = X*64;
	DiceRECT.top = Y*51;
	DiceRECT.right = DiceRECT.left + 64;
	DiceRECT.bottom = DiceRECT.top + 51;
	
	return DiceRECT;
}

void GamePlayState::ChoseWeather(void)
{
	
	WeatherType = rand() % 3 + 1; //correct logic
	
	//test logic
	/*if(WeatherType == 0)
		WeatherType = 1;
	else if(WeatherType == 1)
		WeatherType = 2;
	else if(WeatherType == 2)
		WeatherType = 1;*/
}

void GamePlayState::PotRender(void)
{
	char buffer[50];
	sprintf_s(buffer, "%d", GetHealing());
	Font.Print(buffer, GetActiveTile()->GetScreenPosX(), GetActiveTile()->GetScreenPosY(), 3.0f);	

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
}

void GamePlayState::AddToActive(string Particle)
{
	bool found = false;

	vector<string>::iterator iter = ActiveKeys.begin();

	for( ; iter != ActiveKeys.end(); )
	{
		if(iter->find(Particle) == 0)
		{
			++iter;
			found = true;
		}
		else
			++iter;
	}

	if(found == false)
		ActiveKeys.push_back(Particle);
}

void GamePlayState::ItemPurchased(Item* i)
{
	switch(i->GetID())
	{
	case HPOTION:
		{
			HPotions += 1;
			Inventory.push_back(i);
			break;
		}

	case MPOTION:
		{
			MPotions += 1;
			Inventory.push_back(i);
			break;
		}

	case INHALER:
		{
			Inhalers += 1;
			Inventory.push_back(i);
			break;
		}

	case KN_WPN:
		{
			break;
		}

	case KN_ARM:
		{
			break;
		}

	case WIZ_WPN:
		{
			break;
		}

	case WIZ_ARM:
		{
			break;
		}

	case ARCH_WPN:
		{
			break;
		}

	case ARCH_ARM:
		{
			break;
		}

	case RG_WPN:
		{
			break;
		}

	case RG_ARM:
		{
			break;
		}

	default:
		break;
	};
}

void GamePlayState::EquipItem(Item * item)
{
	switch(item->GetID())
	{
	case KN_ARM:
		{
			
			break;
		}
	case KN_WPN:
		{

			break;
		}
	case WIZ_WPN:
		{

			break;
		}
	case WIZ_ARM:
		{

			break;
		}
	case ARCH_WPN:
		{

			break;
		}
	case ARCH_ARM:
		{

			break;
		}
	case RG_WPN:
		{

			break;
		}
	case RG_ARM:
		{

			break;
		}
	};
}

void GamePlayState::MapSelectInput()
{

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(mapSelection > 0)
			mapSelection -= 1;
		else
			mapSelection = 3;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(mapSelection < 3)
			mapSelection += 1;
		else
			mapSelection = 0;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		switch(mapSelection)
		{
		case 0:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				mapToUse = 0;
				//Game::GetInstance()->SetMap(0);
				StartGame = true;
				break;
			}
		case 1:
			{
				if(map2Unlocked)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					mapToUse = 1;
					//Game::GetInstance()->SetMap(1);
					StartGame = true;
				}

				else
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					return;
				}
				break;
			}
		case 2:
			{
				if(map3Unlocked)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					mapToUse = 2;
					//Game::GetInstance()->SetMap(2);
					StartGame = true;
				}

				else
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					return;
				}

				break;
			}
		case 3:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
				//mapSelectBool = false;
				//tutStart = true;
				//Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				//return;
				Save = true;
				break;
			}
		}

		if(mapSelection < 0 || mapSelection > 2)
			return;

		switch(mapSelection)
		{
		case 0:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				gameGrid->CreateGrid("ForestMap.xml");
				
				break;
			}
		case 1:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				gameGrid->CreateGrid("IndoorMap.xml");
				break;
			}
		case 2:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				gameGrid->CreateGrid("LavaMap.xml");
				break;
			}
		};
		
		size_t size;
		TCHAR buffer[128] = {};
		mbstowcs_s(&size,buffer,128,(gameGrid->GetTileSetFile()),128);

		tileBmpID = CSGD_TextureManager::GetInstance()->LoadTexture(buffer);
		gameGrid->SetTileBmpID(this->tileBmpID);

		

		if(mapSelection == 1)
		{
			int x[5] = { 0, 0, 0, 0, 0};
			int y[5] = { 0, 0, 0, 0, 0};
			int indexX = 0;
			int indexY = 0;

			for(int i = 0; i < gameGrid->GetSizeX(); i++)
			{
				for(int j = 0; j < gameGrid->GetSizeY(); j++)
				{
					string temp = "enemySpawnPoint";
					if(gameGrid->GetTile(i, j)->GetEventString() == temp)
					{
						if(gameGrid->GetTile(i,j)->GetCharacter() == nullptr)
						{
							if(indexX < 5 || indexY < 5)
							{
								x[indexX] = i;
								y[indexY] = j;
								indexX++;
								indexY++;
							}
						}
					}
				}
			}
			
			CreateCharacterMessage* pMsg13 = new CreateCharacterMessage(false, KNIGHT,		x[0], y[0]);
			CreateCharacterMessage* pMsg14 = new CreateCharacterMessage(false, ROGUE,		x[1], y[1]);
			CreateCharacterMessage* pMsg15 = new CreateCharacterMessage(false, ARCHER,		x[2], y[2]);
			CreateCharacterMessage* pMsg16 = new CreateCharacterMessage(false, WIZARD,		x[3], y[3]);
			CreateCharacterMessage* pMsg17 = new CreateCharacterMessage(false, BLACK_KNIGHT,x[4], y[4]);
			MS->SendMsg(pMsg13);
			MS->SendMsg(pMsg14);
			MS->SendMsg(pMsg15);
			MS->SendMsg(pMsg16);
			MS->SendMsg(pMsg17); 
			
		}
		else
		{
			
			int x[5] = { 0, 0, 0, 0, 0};
			int y[5] = { 0, 0, 0, 0, 0};
			int indexX = 0;
			int indexY = 0;

			for(int i = 0; i < gameGrid->GetSizeX(); i++)
			{
				for(int j = 0; j < gameGrid->GetSizeY(); j++)
				{
					string temp = "enemySpawnPoint";
					if(gameGrid->GetTile(i, j)->GetEventString() == temp)
					{
						if(gameGrid->GetTile(i,j)->GetCharacter() == nullptr)
						{
							if(indexX < 5 || indexY < 5)
							{
								x[indexX] = i;
								y[indexY] = j;
								indexX++;
								indexY++;
							}
						}
					}
				}
			}

			CreateCharacterMessage* pMsg13 = new CreateCharacterMessage(false, KNIGHT,		x[0], y[0]);
			CreateCharacterMessage* pMsg14 = new CreateCharacterMessage(false, ROGUE,		x[1], y[1]);
			CreateCharacterMessage* pMsg15 = new CreateCharacterMessage(false, ARCHER,		x[2], y[2]);
			CreateCharacterMessage* pMsg16 = new CreateCharacterMessage(false, WIZARD,		x[3], y[3]);
			CreateCharacterMessage* pMsg17 = new CreateCharacterMessage(false, BLACK_KNIGHT,x[4], y[4]);
			/*MS->SendMsg(pMsg);
			MS->SendMsg(pMsg1);
			MS->SendMsg(pMsg10);
			MS->SendMsg(pMsg11);
			MS->SendMsg(pMsg12);*/
			MS->SendMsg(pMsg13);
			MS->SendMsg(pMsg14);
			MS->SendMsg(pMsg15);
			MS->SendMsg(pMsg16);
			MS->SendMsg(pMsg17); 
			
		}
		
		MPotions = 0;
		Gold = 500;
		//Load = false;
		LoadFailed = false;
		File = 0;
		for(int i = 0; i < 2;i++)
		{
			Item * pot = new Item(HPOTION);
			enemyInventory.push_back(pot);
		}

		mapSelectBool = false;
		StartGame = true;
		
	}
}

void GamePlayState::MapSelectRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(BackgroundID,0,-138,0.8f,0.72f);

	pTM->Draw(PanelID, 170, 30, 2.6f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 170, 65, 2.6f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	pTM->Draw(PanelID, 190, 170, 2.8f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 190, 220, 2.8f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 190, 320, 2.8f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 190, 385, 2.8f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	Font.Print("Map Select", 200, 30, 3.0f);
	Font.Print("Forest Map", 210, 170,2.0f);

	if(map2Unlocked)
	Font.Print("Castle Map", 210, 230,2.0f);

	else
	Font.Print("Castle Map (Locked)", 210, 230,2.0f);

	if(map3Unlocked)
	Font.Print("Mountain Map", 210, 290,2.0f);

	else
	Font.Print("Mountain Map (Locked)", 210, 290,2.0f);

	Font.Print("Back", 210, 350, 2.0f);

	switch(mapSelection)
	{
	case 0:
		CSGD_TextureManager::GetInstance()->Draw(CursorID, 180, 195);
		break;
		
	case 1:
		CSGD_TextureManager::GetInstance()->Draw(CursorID, 180, 255);
		break;

	case 2:
		CSGD_TextureManager::GetInstance()->Draw(CursorID, 180, 315);
		break;

	case 3:
		CSGD_TextureManager::GetInstance()->Draw(CursorID, 180, 375);
		break;
	};
}

void GamePlayState::LoadInput()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(File > 0)
			File -= 1;
		else
			File = 4;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(File < 4)
			File += 1;
		else
			File = 0;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		switch(File)
		{
		case 0:
			{
				tutStart = true;
				Load = false;
				
				break;
			}

		case 1:
			{
				if(LoadSave(1) == true)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Load = false;
					File = 0;
					LoadFailed = false;
					if(!InProgress)
						this->mapSelectBool = true;
				}
				else
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					LoadFailed = true;
				}
				break;
			}

		case 2:
			{
				if(LoadSave(2) == true)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Load = false;
					File = 0;
					LoadFailed = false;
					if(!InProgress)
						mapSelectBool = true;
				}
				else
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					LoadFailed = true;
				}
				break;
			}

		case 3:
			{
				if(LoadSave(3) == true)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Load = false;
					File = 0;
					LoadFailed = false;
					if(!InProgress)
						mapSelectBool = true;
				}
				else
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					LoadFailed = true;
				}
				break;
			}

		case 4:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				tutStart = true;
				Load = false;
				
				Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				break;
			}
		};
	}
}

void GamePlayState::LoadRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(BackgroundID,0,-138,0.8f,0.72f);
	
	pTM->Draw(PanelID, 150, 30, 2.0f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 150, 65, 2.0f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	
	pTM->Draw(PanelID, 220, 170, 1.5f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 220, 1.5f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 320, 1.5f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 385, 1.5f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));


	Font.Print("Load", 270, 30, 3.0f);
	Font.Print("New Game", 250, 170, 2.0f);
	Font.Print("Slot 1", 250, 220, 2.0f);
	Font.Print("Slot 2", 250, 270, 2.0f);
	Font.Print("Slot 3", 250, 320, 2.0f);
	Font.Print("Back", 250, 370, 2.0f);

	switch(File)
	{
	case 0:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 230, 195);
			break;
		}

	case 1:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 230, 245);
			break;
		}

	case 2:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 230, 295);
			break;
		}

	case 3:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 230, 345);
			break;
		}

	case 4:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 230, 395);
			break;
		}
	}
}

void GamePlayState::TutorialInput()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);

		if(tutChoice > 0)
			tutChoice--;

		else
			tutChoice = 3;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(tutChoice < 3)
			tutChoice++;
		
		else
			tutChoice = 0;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		switch(tutChoice)
		{
		case 0:
			CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
			Game::GetInstance()->ChangeState(TutorialPlayState::GetInstance());
			break;

		case 1:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				tutStart = false;
				//StartGame = true;
				for(unsigned int i = 0; i < 4;i++)
				{
					BaseCharacter * c;

					switch(i+1)
					{
					case KNIGHT:
						{
							c = new Knight(true);
							break;
						}
					case ARCHER:
						{
							c = new Archer(true);
							break;
						}
					case ROGUE:
						{
							c = new Rogue(true);
							break;
						}
					case WIZARD:
						{
							c = new Wizard(true);
							break;
						}
					case BLACK_KNIGHT:
						{
							c = new BlackKnight(true);
							break;
						}

					};
					//SizeOfParty++;
					selectFrom.push_back(c);
					//c->Release();
				}
				selected.clear();
				leftSideSelecting = true;
				mapSelectBool = true;
			}
			break;

		case 2:
			CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
			tutStart = false;
			Load = true;
			File = 0;
			break;

		case 3:
			CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
			Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
			break;
		}
	}
}

void GamePlayState::TutorialRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(BackgroundID,0,-138,0.8f,0.72f);

	pTM->Draw(PanelID, 150, 30, 2.6f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 150, 65, 2.6f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	pTM->Draw(PanelID, 230, 170, 1.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 230, 220, 1.4f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 230, 320, 1.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 230, 385, 1.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	Font.Print("View Tutorial?", 170, 30, 3.0f);
	Font.Print("Yes", 300, 180, 2.0f);
	Font.Print("No", 300, 240, 2.0f);
	Font.Print("Back", 300, 300, 2.0f);
	Font.Print("Exit", 300, 360, 2.0f);

	CSGD_TextureManager::GetInstance()->Draw(CursorID, 270, 200 + (tutChoice * 60) );

}

void GamePlayState::ShopInput()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if((!Items && !Equip && !Chars) || Items)
		{
			if(ShopChoice > 0)
				ShopChoice -= 1;
			else
				ShopChoice = 3;
		}
		else if((Equip && !KnEquip && !ArchEquip && !WizEquip && !RgEquip) || Chars)
		{
			if(ShopChoice > 0)
				ShopChoice -= 1;
			else
				ShopChoice = 4;
		}
		else if((KnEquip && Equip) || (ArchEquip && Equip) || (RgEquip && Equip) || (WizEquip && Equip))
		{
			if(ShopChoice > 0)
				ShopChoice -= 1;
			else
				ShopChoice = 2;
		}
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if((!Items && !Equip && !Chars) || Items)
		{
			if(ShopChoice < 3)
				ShopChoice += 1;
			else
				ShopChoice = 0;
		}
		else if(Equip || Chars)
		{
			if(ShopChoice < 4)
				ShopChoice += 1;
			else
				ShopChoice = 0;
		}
		else if(KnEquip || ArchEquip || RgEquip || WizEquip)
		{
			if(ShopChoice < 2)
				ShopChoice += 1;
			else
				ShopChoice = 0;
		}
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		if(!Items && !Equip && !Chars)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Items = true;
					ShopChoice = 0;
					break;
				}
			case 1:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Equip = true;
					ShopChoice = 0;
					break;
				}
			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Chars = true;
					ShopChoice = 0;
					break;
				}
			case 3:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					ShopMenu = false;
					StartGame = true;
					ShopChoice = 0;
					CSGD_XAudio2::GetInstance()->MusicStopSong(ShopBGM);
					CSGD_XAudio2::GetInstance()->MusicPlaySong(BGMID, true);
					break;
				}
			};
		}
		else if(Items && !Equip && !Chars)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 10)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(0);
						ItemPurchased(i);
						Gold -= 10;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 1:
				{
					if(Gold >= 20)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(1);
						ItemPurchased(i);
						Gold -= 20;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 2:
				{
					if(Gold >= 15)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(2);
						ItemPurchased(i);
						Gold -= 15;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 3:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					Items = false;
					ShopChoice = 0;
					break;
				}
			};
		}
		else if(Chars && !Equip && !Items)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 100)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						BaseCharacter* Kn = new Knight(true);
						selectFrom.push_back(Kn);
						Gold -= 100;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

					break;
				}
			case 1:
				{
					if(Gold >= 100)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						BaseCharacter* Wiz = new Wizard(true);
						selectFrom.push_back(Wiz);
						Gold -= 100;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

					break;
				}
			case 2:
				{
					if(Gold >= 100)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						BaseCharacter* Arch = new Archer(true);
						selectFrom.push_back(Arch);
						Gold -= 100;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

					break;
				}
			case 3:
				{
					if(Gold >= 100)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						BaseCharacter* Rg = new Rogue(true);
						selectFrom.push_back(Rg);
						Gold -= 100;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);

					break;
				}
			case 4:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					Chars = false;
					ShopChoice = 0;
					break;
				}
			};
		}
		else if(Equip && !Items && !Chars && !KnEquip && !ArchEquip && !WizEquip && !RgEquip)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					KnEquip = true;
					ShopChoice = 0;
					break;
				}
			case 1:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					ArchEquip = true;
					ShopChoice = 0;
					break;
				}
			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					WizEquip = true;
					ShopChoice = 0;
					break;
				}
			case 3:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					RgEquip = true;
					ShopChoice = 0;
					break;
				}
			case 4:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					Equip = false;
					ShopChoice = 0;
					break;
				}
			}
		}
		else if(KnEquip && Equip)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 50 && KWpn)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(3);
						i->SetName("Foam Sword");
						i->SetVal(4);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == KNIGHT)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						KWpn = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 1:
				{
					if(Gold >= 50 && KArm)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(4);
						i->SetName("Boxite Armor");
						i->SetVal(4);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == KNIGHT)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						KArm = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					KnEquip = false;
					ShopChoice = 0;
					break;
				}
			};
		}
		else if(RgEquip && Equip)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 50 && RWpn)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(9);
						i->SetName("Plastic Daggers");
						i->SetVal(2);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == ROGUE)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						RWpn = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 1:
				{
					if(Gold >= 50 && RArm)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(10);
						i->SetName("Worn Pajamas");
						i->SetVal(2);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == ROGUE)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						RArm = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					RgEquip = false;
					ShopChoice = 0;
					break;
				}
			};
		}
		else if(WizEquip && Equip)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 50 && WWpn)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(5);
						i->SetName("Flimsy Staff");
						i->SetVal(4);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == WIZARD)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						WWpn = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 1:
				{
					if(Gold >= 50 && WArm)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(6);
						i->SetName("Old Bathrobe");
						i->SetVal(2);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == WIZARD)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						WArm = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					WizEquip = false;
					ShopChoice = 0;
					break;
				}
			};
		}
		else if(ArchEquip && Equip)
		{
			switch(ShopChoice)
			{
			case 0:
				{
					if(Gold >= 50 && AWpn)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(7);
						i->SetName("Toy Bow");
						i->SetVal(2);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == ARCHER)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						AWpn = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 1:
				{
					if(Gold >= 50 && AArm)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						Item* i = new Item(8);
						i->SetName("Tight Tights");
						i->SetVal(2);
						vector<BaseCharacter*>::iterator iter;
						iter = selectFrom.begin();
						for( ; iter != selectFrom.end(); ++iter)
						{
							if((*iter)->GetType() == ARCHER)
								if((*iter)->IsPlayer())
								i->ApplyEffect(i->GetID(), *iter);
						}
						AArm = false;
						Inventory.push_back(i);
						Gold -= 50;
					}

					else
						CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
					break;
				}

			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					ArchEquip = false;
					ShopChoice = 0;
					break;
				}
			};
		}
	}
}

void GamePlayState::ShopRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(ShopBmp,0,0,1.0f,1.0f);
	char cash[10];
	sprintf_s(cash, "%d", Gold);
	Font.Print(cash, 390, 525, 2.0f);
	Font.Print("GP", 290, 525, 2.0f);
	if(!Items && !Equip && !Chars)
	{
		Font.Print("What are ya buyin'?", 50, 200, 2.0f);
		Font.Print("Items", 50, 275, 2.0f);
		Font.Print("Equipment", 50, 325, 2.0f);
		Font.Print("Characters", 50, 375, 2.0f);
		Font.Print("Exit", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				Font.Print("Purchase healing items", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				Font.Print("Buy new equipment", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				Font.Print("Buy additional characters", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 400);
				break;
			}
		case 3:
			{
				Font.Print("Commence battle!", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
	else if(Items)
	{
		Font.Print("Item", 50, 200, 2.0f);
		Font.Print("Cost", 650, 200, 2.0f);
		Font.Print("Potion", 50, 275, 2.0f);
		Font.Print("10 GP", 630, 275, 2.0f);
		Font.Print("Ether", 50, 325, 2.0f);
		Font.Print("20 GP", 620, 325, 2.0f);
		Font.Print("Inhaler", 50, 375, 2.0f);
		Font.Print("15 GP", 630, 375, 2.0f);
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				Font.Print("Restores the user's health to full.", 300, 50, 1.0f);
				Font.Print("Now with refreshing cherry flavor!", 300, 100, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				Font.Print("Restores the user's mana to full.", 300, 50, 1.0f);
				Font.Print("Wizards only!", 300, 100, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				Font.Print("For relieving severe allergies.", 300, 50, 1.0f);
				Font.Print("Follow your doctor's orders when using.", 300, 100, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 400);
				break;
			}

		case 3:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
	else if(Chars)
	{
		Font.Print("Class", 650, 200, 2.0f);
		Font.Print("Knight", 50, 275, 2.0f);
		Font.Print("100 GP", 630, 275, 2.0f);
		Font.Print("Wizard", 50, 325, 2.0f);
		Font.Print("100 GP", 620, 325, 2.0f);
		Font.Print("Archer", 50, 375, 2.0f);
		Font.Print("100 GP", 630, 375, 2.0f);
		Font.Print("Rogue", 50, 425, 2.0f);
		Font.Print("100 GP", 630, 425, 2.0f);
		Font.Print("Back", 50, 475, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				Font.Print("Cardboard armor gives him high defense.", 300, 50, 1.0f);
				Font.Print("It's hard to move in, though.", 300, 100, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				Font.Print("Better buy some Ethers!", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				Font.Print("A very generic archer.", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 400);
				break;
			}

		case 3:
			{
				Font.Print("Fights dirty.", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		case 4:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 500);
				break;
			}
		};
	}
	else if(Equip && !KnEquip && !ArchEquip && !WizEquip && !RgEquip)
	{
		Font.Print("Knights", 50, 225, 2.0f);
		Font.Print("Archers", 50, 275, 2.0f);
		Font.Print("Wizards", 50, 325, 2.0f);
		Font.Print("Rogues", 50, 375, 2.0f);
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 250);
				break;
			}

		case 1:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 3:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 400);
				break;
			}
		case 4:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
			}
		};
	}
	else if(KnEquip && Equip)
	{
		Font.Print("Item", 50, 200, 2.0f);
		Font.Print("Cost", 650, 200, 2.0f);
		if(KWpn)
		{
			Font.Print("Foam Sword", 50, 275, 2.0f);
			Font.Print("50 GP", 630, 275, 2.0f);
		}
		if(KArm)
		{
			Font.Print("Boxite Armor", 50, 325, 2.0f);
			Font.Print("50 GP", 620, 325, 2.0f);
		}
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				if(KWpn)
					Font.Print("+4 Attack", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				if(KArm)
					Font.Print("+4 defense", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
	else if(ArchEquip && Equip)
	{
		Font.Print("Item", 50, 200, 2.0f);
		Font.Print("Cost", 650, 200, 2.0f);
		if(AWpn)
		{
			Font.Print("Toy Bow", 50, 275, 2.0f);
			Font.Print("50 GP", 630, 275, 2.0f);
		}
		if(AArm)
		{
			Font.Print("Tight Tights", 50, 325, 2.0f);
			Font.Print("50 GP", 620, 325, 2.0f);
		}
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				if(AWpn)
					Font.Print("+2 Attack", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				if(AArm)
					Font.Print("+2 defense", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
	else if(WizEquip && Equip)
	{
		Font.Print("Item", 50, 200, 2.0f);
		Font.Print("Cost", 650, 200, 2.0f);
		if(WWpn)
		{
			Font.Print("Flimsy Staff", 50, 275, 2.0f);
			Font.Print("50 GP", 630, 275, 2.0f);
		}
		if(WArm)
		{
			Font.Print("Old Bathrobe", 50, 325, 2.0f);
			Font.Print("50 GP", 620, 325, 2.0f);
		}
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				if(WWpn)
					Font.Print("+4 Attack", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				if(WArm)
					Font.Print("+2 defense", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
	else if(RgEquip && Equip)
	{
		Font.Print("Item", 50, 200, 2.0f);
		Font.Print("Cost", 650, 200, 2.0f);
		if(RWpn)
		{
			Font.Print("Plastic Daggers", 50, 275, 2.0f);
			Font.Print("50 GP", 630, 275, 2.0f);
		}
		if(RArm)
		{
			Font.Print("Worn Pajamas", 50, 325, 2.0f);
			Font.Print("50 GP", 620, 325, 2.0f);
		}
		Font.Print("Back", 50, 425, 2.0f);

		switch(ShopChoice)
		{
		case 0:
			{
				if(RWpn)
					Font.Print("+2 Attack", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 300);
				break;
			}

		case 1:
			{
				if(RArm)
					Font.Print("+2 defense", 300, 50, 1.0f);
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 350);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, 30, 450);
				break;
			}
		};
	}
}

void GamePlayState::SaveInput()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(File > 0)
			File -= 1;
		else
			File = 4;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(File < 4)
			File += 1;
		else
			File = 0;
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		switch(File)
		{
		case 0:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				
				if(InProgress)
				{
					if(!gameWon && !gameWon2)
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
					else
					{
						mapSelectBool = true;
						InProgress = false;
						gameWon = false;
						gameWon2 = false;
					}
				}
				else
				{
					if(!mapSelectBool)
						mapSelectBool = true;
					else
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
				}
				SaveGame(activeTile, Characters, 1);


				Save = false;

				break;
			}

		case 1:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				
				if(InProgress)
				{
					if(!gameWon && !gameWon2)
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
					else
					{
						mapSelectBool = true;
						InProgress = false;
						gameWon = false;
						gameWon2 = false;
					}
				}
				else
				{
					if(!mapSelectBool)
						mapSelectBool = true;
					else
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
				}
				SaveGame(activeTile, Characters, 2);

				Save = false;

				break;
			}

		case 2:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
				
				if(InProgress)
				{
					if(!gameWon && !gameWon2)
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
					else
					{
						mapSelectBool = true;
						InProgress = false;
						gameWon = false;
						gameWon2 = false;
					}
				}
				else
				{
					if(!mapSelectBool)
						mapSelectBool = true;
					else
					{
						Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
						return;
					}
				}
				SaveGame(activeTile, Characters, 3);

				Save = false;

				break;
			}

		case 3:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
				if(InProgress)
				{
					Save = false;
					Paused = true;
				}
				else if(mapSelectBool )
				{
					Save = false;
					mapSelectBool = true;
					InProgress = false;
					gameWon = false;
					gameWon2 = false;
				}
				else
				{
					Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
					return;
				}
				break;
			}

		case 4:
			{
				CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
				Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
				break;
			}
		};
	}
}

void GamePlayState::SaveRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};
	
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(BackgroundID,0,-138,0.8f,0.72f);
	
	pTM->Draw(PanelID, 150, 30, 2.0f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 150, 65, 2.0f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	
	pTM->Draw(PanelID, 220, 170, 1.5f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 220, 1.5f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 320, 1.5f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 220, 385, 1.5f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));


	Font.Print("Save", 270, 30, 3.0f);
	Font.Print("Slot 1", 250, 170, 2.0f);
	Font.Print("Slot 2", 250, 220, 2.0f);
	Font.Print("Slot 3", 250, 270, 2.0f);
	Font.Print("Back", 250, 320, 2.0f);
	Font.Print("Exit", 250, 370, 2.0f);

	switch(File)
	{
	case 0:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 195);
			break;
		}

	case 1:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 245);
			break;
		}

	case 2:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 295);
			break;
		}

	case 3:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 345);
			break;
		}
			
	case 4:
		{
			CSGD_TextureManager::GetInstance()->Draw(CursorID, 210, 395);
			break;
		}
	};
}

void GamePlayState::PrebattleInput()
{
	CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();

	if(di->KeyPressed(DIK_BACKSPACE) || arcadeBackspace)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
		prebattle = false;
		StartGame = true;

		for(unsigned int i = 0; i < selected.size();i++)
		{
			selectFrom.push_back(selected[i]);
			selected.erase(selected.begin()+i);
			//preLeftSelection = 0;
			i--;
		}
	}

	if(di->KeyPressed(DIK_UP)||arcadeUp)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(this->leftSideSelecting)
		{
			this->preLeftSelection--;
			if(preLeftSelection < 0)
				preLeftSelection = selectFrom.size()-1;
		}
		else
		{
			this->preRightSelection--;
			if(preRightSelection < 0)
				preRightSelection = selected.size()-1;
		}
	}

	if(di->KeyPressed(DIK_DOWN)||arcadeDown)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		if(this->leftSideSelecting)
		{
			this->preLeftSelection++;
			if(preLeftSelection >= (int)selectFrom.size())
				preLeftSelection = 0;
		}
		else
		{
			this->preRightSelection++;
			if(preRightSelection >= (int)selected.size())
				preRightSelection = 0;
		}
	}

	if(di->KeyPressed(DIK_LEFT)||arcadeLeft)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		preLeftSelection = 0;
		this->leftSideSelecting = true;
	}

	if(di->KeyPressed(DIK_RIGHT)||arcadeRight)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		preRightSelection = 0;
		if(selected.size() > 0)
			this->leftSideSelecting = false;
	}

	if(di->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
		if(this->leftSideSelecting)
		{
			selected.push_back(selectFrom[preLeftSelection]);
			selectFrom.erase(selectFrom.begin()+preLeftSelection);
			preLeftSelection = 0;
		}
		else
		{
			selectFrom.push_back(selected[preRightSelection]);
			selected.erase(selected.begin()+preRightSelection);
			preRightSelection = 0;
			if(selected.size() <= 0)
				leftSideSelecting = true;
		}

		if(selected.size() == 4)
		{
			for(unsigned int i = 0; i < selected.size();i++)
			{
				//TakeCharacterMsg* pMSG = new TakeCharacterMsg(selected[i]);
				//MS->SendMsg(pMSG);
				this->CharactersToTake.push_back(selected[i]);
				SizeOfParty++;
			}

			for(unsigned int i = 0; i < CharactersToTake.size();i++)
			{
				CharactersToTake[i]->SetMoved(false);
				CharactersToTake[i]->SetActed(false);
			}

			SelectingaTile = true;
			SelectingCount = 0;
			InProgress = true;
			prebattle = false;

			for(int x = 0; x < gameGrid->GetSizeX();x++)
			{
				for(int y = 0; y < gameGrid->GetSizeY();y++)
				{
					string tempS = gameGrid->GetTile(x,y)->GetEventString();
					if(tempS == "playerSpawnPoint")
					{
						gameGrid->GetTile(x,y)->HighlightTile(true,0,255,0,100);
					}
				}
			}

		}

	}
}

void GamePlayState::PrebattleRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};

	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)) - 10, 73, 1.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)) - 10, 113, 1.7f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	Font.Print("Select Fighters",(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.7f)),83,2.0f);

	//Font.Print("Take into Battle",(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),100,2.0f);

	pTM->Draw(PanelID, 50, 150, 1.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 50, 200, 1.4f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 50, 300, 1.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 50, 365, 1.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	if(this->leftSideSelecting)
		CSGD_TextureManager::GetInstance()->Draw(this->CursorID,(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.93f)),155+(this->preLeftSelection*30));
	else
		CSGD_TextureManager::GetInstance()->Draw(this->CursorID,(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.53f)),155+(this->preRightSelection*30));



	for(unsigned int i = 0; i < selectFrom.size();i++)
	{
		string s;

		switch(selectFrom[i]->GetType())
		{
		case KNIGHT:
			{
				s = "Cardboard Knight";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),150+(i*30),1.0f);
				break;
			}
		case ARCHER:
			{
				s = "Generic Archer";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),150+(i*30),1.0f);
				break;
			}
		case WIZARD:
			{
				s = "Internet Wizard";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),150+(i*30),1.0f);
				break;
			}
		case ROGUE:
			{
				s = "Obvious Rogue";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),150+(i*30),1.0f);
				break;
			}
		case BLACK_KNIGHT:
			{
				s = "Blackish Knight";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),150+(i*30),1.0f);
				break;
			}
		};
	}

	pTM->Draw(PanelID, 370, 150, 1.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 370, 200, 1.4f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 370, 300, 1.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 370, 365, 1.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	for(unsigned int i = 0; i < selected.size();i++)
	{
		string s;

		switch(selected[i]->GetType())
		{
		case KNIGHT:
			{
				s = "Cardboard Knight";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),150+(i*30),1.0f);
				break;
			}
		case ARCHER:
			{
				s = "Generic Archer";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),150+(i*30),1.0f);
				break;
			}
		case WIZARD:
			{
				s = "Internet Wizard";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),150+(i*30),1.0f);
				break;
			}
		case ROGUE:
			{
				s = "Obvious Rogue";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),150+(i*30),1.0f);
				break;
			}
		case BLACK_KNIGHT:
			{
				s = "Blackish Knight";
				Font.Print(s.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),150+(i*30),1.0f);
				break;
			}
		};
	}

	BaseCharacter * bc;
	if(this->leftSideSelecting)
			bc = selectFrom[preLeftSelection];
	else
			bc = selected[preRightSelection];

	pTM->Draw(PanelID, 65, 420, 2.4f, 1.8f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 65, 470, 2.4f, 2.1f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, 65, 540, 2.4f, 1.8f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	string sBuffer = "Stats:";
	char cBuffer[8];
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f)),1.0f);
			
	sprintf_s(cBuffer, "%d", bc->GetLevel());		
	sBuffer = "Level: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+30,1.0f);
		
	sprintf_s(cBuffer, "%d", bc->GetExp());		
	sBuffer = "Exp: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+60,1.0f);

	sprintf_s(cBuffer, "%d", bc->GetMaxHP());		
	sBuffer = "Max HP: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+90,1.0f);

	sprintf_s(cBuffer, "%d", bc->GetMov());		
	sBuffer = "Movement: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.9f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+120,1.0f);

	sprintf_s(cBuffer, "%d", bc->GetAtk());		
	sBuffer = "Attack: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+30,1.0f);

	sprintf_s(cBuffer, "%d", bc->GetDef());		
	sBuffer = "Defense: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+60,1.0f);

	sprintf_s(cBuffer, "%d", bc->GetRng());		
	sBuffer = "Range: ";
	sBuffer += cBuffer;
	Font.Print(sBuffer.c_str(),(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.5f)),(int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.3f))+90,1.0f);

	Font.Print("Press Backspace To Return", (int)(Game::GetInstance()->GetWinWidth()*0.6), (int)(Game::GetInstance()->GetWinHeight()*0.93),1.0f);

}

void GamePlayState::GameInput()
{
	TileManager * tm = TileManager::GetInstance();
	if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_LCONTROL) && CSGD_DirectInput::GetInstance()->KeyPressed(DIK_T))
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(twentyID);
		twentyRender = true;  
		//this->gameWon = true;
	}
	

	if(SelectingaTile == false && (CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LSHIFT) || CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RSHIFT)||arcadeShift))
	{
		Tile* temp = gameGrid->ReturnHilightedTile(0);
		if(temp->GetCharacter() != nullptr)
		{
			Viewing = temp->GetCharacter();
			StatsMenu = true;
			Command = false;
			Attack = false;
			Movement = false;
			abilityMenu = false;
			abilityTargeting = false;
		}
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_NUMPADPLUS)||arcadePlus)
	{
		if(tm->GetScale() < 2.0f)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			tm->SetScale(tm->GetScale() * 2.0f);
		}
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_NUMPADMINUS)||arcadeMinus)
	{
		if(tm->GetScale() > 1.0f)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			tm->SetScale(tm->GetScale() / 2.0f);
		}
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_UP)||arcadeUp)
		if(!Command && !ItemMenu && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			cursorMoved = true;
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			cursorY--;
			if(cursorY < 0)
				cursorY = 0;
		}
			//tm->SetPosY(tm->GetPosY()+ tm->GetTileSizeX());// * tm->GetScale()));
		else if(Command && !ItemMenu && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(CmndChoice > 0)
				CmndChoice -= 1;
			else
				CmndChoice = 5;
		}
		else if(ItemMenu && !Command && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(ItemChoice > 0)
				ItemChoice -= 1;
			else
				ItemChoice = 3;
		}
		else if(abilityMenu && !Command && !ItemMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(tm->ReturnHilightedTile(0)->GetCharacter()->GetType() != WIZARD)
			{
				if(abilitySelection >0)
					abilitySelection--;
				else
					abilitySelection = 3;
			}
			else
			{
				if(abilitySelection >0)
					abilitySelection--;
				else
					abilitySelection = 4;
			}
		}
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_DOWN)||arcadeDown)
		if(!Command && !ItemMenu && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			cursorMoved = true;
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			cursorY++;
			if(cursorY >= tm->GetSizeY())
				cursorY = tm->GetSizeY() -1;
		}
			//tm->SetPosY(tm->GetPosY()- tm->GetTileSizeY());// * tm->GetScale()));
		else if(Command && !ItemMenu && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(CmndChoice < 5)
				CmndChoice += 1;
			else
				CmndChoice = 0;
		}
		else if(ItemMenu && !Command && !abilityMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(ItemChoice < 3)
				ItemChoice += 1;
			else
				ItemChoice = 0;
		}
		else if(abilityMenu && !Command && !ItemMenu)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
			if(tm->ReturnHilightedTile(0)->GetCharacter()->GetType() != WIZARD)
			{
				if(abilitySelection < 3)
					abilitySelection++;
				else
					abilitySelection = 0;
			}
			else
			{
				if(abilitySelection < 4)
					abilitySelection++;
				else
					abilitySelection = 0;
			}
		}
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT)||arcadeLeft)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		cursorMoved = true;
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		cursorX--;
		if(cursorX < 0)
			cursorX = 0;
	}
		//tm->SetPosX(tm->GetPosX()+ tm->GetTileSizeX());// * tm->GetScale()));
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT)||arcadeRight)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		cursorMoved = true;
		CSGD_XAudio2::GetInstance()->SFXPlaySound(moveID);
		cursorX++;
		if(cursorX >= tm->GetSizeX())
			cursorX = tm->GetSizeX()-1;
	}
		//tm->SetPosX(tm->GetPosX()- tm->GetTileSizeX());// * tm->GetScale()));

	if(cursorMoved)
	{
		
		RECT cursorRect;
		cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
		cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

		if(AImoving == true)
		{
			cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(activeTile->GetX()*tm->GetScale()*tm->GetTileSizeX()));
			cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(activeTile->GetY()*tm->GetScale()*tm->GetTileSizeY()));
			cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
			cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));
		}

		if(cursorRect.left < 0)
		{
			if(AImoving == true)
				tm->SetPosX(-activeTile->GetX()*tm->GetTileSizeX());
			else
				tm->SetPosX(-cursorX*tm->GetTileSizeX());
		}
		if(cursorRect.right > Game::GetInstance()->GetWinWidth())
		{
			if(AImoving == true)
				tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(activeTile->GetX()+1)*tm->GetTileSizeX()));
			else
				tm->SetPosX((int)((Game::GetInstance()->GetWinWidth())/tm->GetScale()-(cursorX+1)*tm->GetTileSizeX()));//cursorRect.right/tm->GetScale());//((cursorX*tm->GetTileSizeX())-(tm->GetTileSizeX()*tm->GetScale()))*tm->GetScale());
		}
		if(cursorRect.top < 0)
		{
			if(AImoving == true)
				tm->SetPosY(-activeTile->GetY()*tm->GetTileSizeY());
			else
				tm->SetPosY(-cursorY*tm->GetTileSizeY());
		}
		if(cursorRect.bottom > Game::GetInstance()->GetWinHeight())
		{
			if(AImoving == true)
				tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(activeTile->GetY()+1)*tm->GetTileSizeY()));
			else
				tm->SetPosY((int)((Game::GetInstance()->GetWinHeight())/tm->GetScale()-(cursorY+1)*tm->GetTileSizeY()));//((cursorY*tm->GetTileSizeY())-(tm->GetTileSizeY()*tm->GetScale()))*tm->GetScale());
		}
	}

	if(AImoving == false)
	{

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)||arcadeEnter)
	{
		if(!Movement && !Attack && !Command && !ItemMenu&& !abilityMenu && !abilityTargeting && !StatsMenu && !SelectingaTile)
		{
			activeTile = tm->ReturnHilightedTile(0);
			if(activeTile->GetCharacter() != nullptr && (activeTile->GetCharacter()->IsPlayer() == playerTurn) && !activeTile->GetCharacter()->IsDead())
			{
				Command = true;
				switch(activeTile->GetCharacter()->GetType())
				{
				case KNIGHT:
					activeTile->GetCharacter()->ChangeState(9);
					break;
				
				case WIZARD:
					activeTile->GetCharacter()->ChangeState(15);
					break;
				
				case ROGUE:
					activeTile->GetCharacter()->ChangeState(22);
					break;

				case ARCHER:
					activeTile->GetCharacter()->ChangeState(28);
					break;

				case BLACK_KNIGHT:
					activeTile->GetCharacter()->ChangeState(38);
					break;
				}
			}
		}
		else if(Movement && !Attack && !Command && !ItemMenu&& !abilityMenu && !abilityTargeting && !StatsMenu && !SelectingaTile)
		{
			Tile * selected = tm->ReturnHilightedTile(0);
			if(selected->GetCharacter() == nullptr)
			{
				if(activeTile->GetCharacter()->Move(selected))
				{
					Movement = false;
					//selected->GetCharacter()->SetMoved(false);
				}
				else
				{
					this->StartActionWindow(42);
				}
			}
			else
			{
				this->StartActionWindow(42);
			}
		}
		else if(Attack && !Movement && !Command && !ItemMenu&& !abilityMenu && !abilityTargeting && !StatsMenu && !SelectingaTile)
		{
			Tile * selected = tm->ReturnHilightedTile(0);
			if(selected->GetCharacter() != nullptr && selected->GetCharacter()->IsPlayer() != playerTurn)
			{
				if(activeTile->GetCharacter()->Attack(selected))
				{
					Attack = false;
					Throw = true;
					SpellHit = false;
					playVoice = true;
					tm->ResetHighlights();
				}
				else
				{
					this->StartActionWindow(42);
				}
			}
			else
			{
				this->StartActionWindow(42);
			}
		}
		else if(Command && !Attack && !Movement && !ItemMenu&& !abilityMenu && !abilityTargeting && !StatsMenu && !SelectingaTile)
		{
			switch(CmndChoice)
			{
			case 0:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Movement = true;
					this->StartActionWindow(MOVE2);
					HighlightMove();
					break;
				}

			case 1:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					Attack = true;
					this->StartActionWindow(ATTACK2);

					HighlightAction(true,activeTile->GetCharacter()->GetRng());
					break;
				}

			case 2:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					abilityMenu = true;
					break;
				}
			case 3:
				{

					if(!activeTile->GetCharacter()->UseAbility(GUARD,activeTile))
						this->StartActionWindow(42);
					else
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						this->StartActionWindow(GUARD);
					}
					break;
				}
			case 4:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
					ItemMenu = true;
					break;
				}

			case 5:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					Command = false;
					break;
				}
			};
			Command = false;
		}
		else if(ItemMenu && !Command && !Attack && !Movement && !abilityMenu && !StatsMenu && !SelectingaTile)
		{
			switch(ItemChoice)
			{
			case 0:
				{
					if(HPotions != 0)
					{
						vector<Item*>::iterator iter = Inventory.begin();
						for( ; iter != Inventory.end(); ++iter)
						{
							if((*iter)->GetID() == HPOTION)
							{
								if(activeTile->GetCharacter()->UseItem(*iter))
								{
									HPotions -= 1;
									delete(*iter);
									Inventory.erase(iter);
									ItemMenu = false;
									this->StartActionWindow(HPOTION2);

									break;
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}
						}
					}
					else
						break;
				}

			case 1:
				{
					if(MPotions != 0)
					{
						vector<Item*>::iterator iter = Inventory.begin();
						for( ; iter != Inventory.end(); ++iter)
						{
							if((*iter)->GetID() == MPOTION)
							{
								if(activeTile->GetCharacter()->UseItem(*iter))
								{
									MPotions -= 1;
									delete(*iter);
									Inventory.erase(iter);
									ItemMenu = false;
									this->StartActionWindow(MPOTION2);

									break;
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}
						}
					}
					else
						break;
				}

			case 2:
				{
					if(Inhalers != 0)
					{
						vector<Item*>::iterator iter = Inventory.begin();
						for( ; iter != Inventory.end(); ++iter)
						{
							if((*iter)->GetID() == INHALER)
							{
								if(activeTile->GetCharacter()->UseItem(*iter))
								{
									Inhalers -= 1;
									delete(*iter);
									Inventory.erase(iter);
									ItemMenu = false;
									this->StartActionWindow(INHALER2);

									break;
								}
								else
									CSGD_XAudio2::GetInstance()->SFXPlaySound(errorID);
									break;
							}
						}
					}
					else
						break;
				}

			case 3:
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
					Command = true;
					ItemMenu = false;
				}
			};
		}
		else if(abilityMenu && !ItemMenu && !Command && !Attack && !Movement && !abilityTargeting && !StatsMenu && !SelectingaTile)
		{
			switch (this->activeTile->GetCharacter()->GetType())
			{
			case WIZARD:
				{
					switch(abilitySelection)
					{
					case 4:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							abilityMenu = false;
							Command = true;
							tm->ResetHighlights();
							break;
						}
					default:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							abilityMenu = false;
							abilityTargeting = true;
							if(abilitySelection == 3)
								HighlightAction(false,1);
							else
								HighlightAction(true,activeTile->GetCharacter()->GetRng());

							switch(abilitySelection)
							{
							case 0:
								{
									this->StartActionWindow(LIGHTNING_BOLT);
									break;
								}
							case 3:
								{
									this->StartActionWindow(PEROXIDE);
									break;
								}
							case 1:
								{
									this->StartActionWindow(FIRE_BALLS);
									break;
								}
							case 2:
								{
									this->StartActionWindow(TSUNAMI);
									break;
								}
							};

							break;
						}
					};
					break;

				}
			case KNIGHT:
				{
					switch(abilitySelection)
					{
					case 3:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							abilityMenu = false;
							Command = true;
							tm->ResetHighlights();
							break;
						}
					case 0:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							this->activeTile->GetCharacter()->UseAbility(REINFORCED_CARDBOARD,activeTile);
							abilityMenu = false;
							this->StartActionWindow(REINFORCED_CARDBOARD);

							break;
						}
					default:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							abilityMenu = false;
							abilityTargeting = true;
							if(abilitySelection == 1)
								HighlightAction(true,1);
							else
								HighlightAction(false,1);

							switch(abilitySelection)
							{
							case 2:
								{
									this->StartActionWindow(COVER);
									break;
								}
							case 1:
								{
									this->StartActionWindow(SHIELD_BASH);
									break;
								}
							};

							break;
						}
					};
					break;
				}
			case ARCHER:
				{
					switch(abilitySelection)
					{
					case 3:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							abilityMenu = false;
							Command = true;
							tm->ResetHighlights();
							break;
						}
					default:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							abilityMenu = false;
							abilityTargeting = true;
							if(abilitySelection == 2)
								HighlightAction(true,activeTile->GetCharacter()->GetRng()+2);
							else
								HighlightAction(true,activeTile->GetCharacter()->GetRng());

							switch(abilitySelection)
							{
							case 1:
								{
									this->StartActionWindow(SHOOT_HARDER);
									break;
								}
							case 2:
								{
									this->StartActionWindow(SHOOT_FARTHER);
									break;
								}
							case 0:
								{
									this->StartActionWindow(MULTI_SHOT);
									break;
								}
							};

							break;
						}
					};
					break;
				}
			case ROGUE:
				{
					switch(abilitySelection)
					{
					case 3:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							abilityMenu = false;
							Command = true;
							tm->ResetHighlights();
							break;
						}
					case 0:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							this->activeTile->GetCharacter()->UseAbility(HIDE,activeTile);
							abilityMenu = false;
							this->StartActionWindow(HIDE);

							break;
						}
					default:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							abilityMenu = false;
							abilityTargeting = true;
							HighlightAction(true,1);

							switch(abilitySelection)
							{
							case 1:
								{
									this->StartActionWindow(BACKSTAB);
									break;
								}
							case 2:
								{
									this->StartActionWindow(INFLICT_ALLERGIES);
									break;
								}
							};

							break;
						}
					};
					break;
				}
			case BLACK_KNIGHT:
				{
					switch(abilitySelection)
					{
					case 3:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(declineID);
							abilityMenu = false;
							Command = true;
							tm->ResetHighlights();
							break;
						}
					case 1:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							this->activeTile->GetCharacter()->UseAbility(BITE_KNEE_CAPS,activeTile);
							abilityMenu = false;
							break;
						}
					case 2:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							this->activeTile->GetCharacter()->UseAbility(GUARD_BRIDGE,activeTile);
							this->StartActionWindow(GUARD_BRIDGE);

							abilityMenu = false;
							break;
						}
					default:
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
							abilityMenu = false;
							abilityTargeting = true;
							this->StartActionWindow(TAUNT);
							break;
						}
					};
					break;
				}
			}
		}
		else if(abilityTargeting && !abilityMenu && !ItemMenu && !Command && !Attack && !Movement && !StatsMenu && !SelectingaTile)
		{
			Tile* selected = tm->ReturnHilightedTile(0);

			CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
			switch(activeTile->GetCharacter()->GetType())
			{
			case WIZARD:
				{
					switch(abilitySelection)
					{
					case 0:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(LIGHTNING_BOLT,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 1:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(FIRE_BALLS,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 2:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(TSUNAMI,selected);


							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}
							break;
						}
					case 3:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(PEROXIDE,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}

					};
					break;
				}
			case KNIGHT:
				{
					switch(abilitySelection)
					{
					case 1:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHIELD_BASH,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 2:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(COVER,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}

					};
					break;
				}
			case ROGUE:
				{
					switch(abilitySelection)
					{
					case 1:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(BACKSTAB,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 2:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(INFLICT_ALLERGIES,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
						
					};
					break;
				}
			case ARCHER:
				{
					switch(abilitySelection)
					{
					case 0:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(MULTI_SHOT,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 1:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHOOT_HARDER,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}
					case 2:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(SHOOT_FARTHER,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}

					};
					break;
				}
			case BLACK_KNIGHT:
				{
					switch(abilitySelection)
					{
					case 0:
						{
							abilityTargeting = !activeTile->GetCharacter()->UseAbility(TAUNT,selected);

							if(abilityTargeting)
							{
								this->StartActionWindow(42);
							}

							break;
						}

					};
					break;
				}

			};

			if(abilityTargeting == false)
			{
				tm->ResetHighlights();
			}

		}
		else if(StatsMenu && !abilityTargeting && !abilityMenu && !ItemMenu && !Command && !Attack && !Movement && !SelectingaTile)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
			StatsMenu = false;
		}
		else if(SelectingaTile && !StatsMenu && !abilityTargeting && !abilityMenu && !ItemMenu && !Command && !Attack && !Movement)
		{
			activeTile = tm->ReturnHilightedTile(0);
			std::string temp = "playerSpawnPoint";

			if(activeTile->GetEventString() == temp)
			{
				if(activeTile->GetCharacter() == nullptr)
				{
					if(SelectingCount != CharactersToTake.size())
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(acceptID);
						CharactersToTake[SelectingCount]->SetTile(activeTile);
						activeTile->SetCharacter(CharactersToTake[SelectingCount]);

						Characters.push_back(CharactersToTake[SelectingCount]);

						SizeOfParty--;

						SelectingCount++;

						activeTile->HighlightTile(false);

					}
				}
				else
				{
					this->StartActionWindow(42);
				}
			}
			else
			{
				this->StartActionWindow(42);
			}

			if((unsigned int)SelectingCount >= CharactersToTake.size())
			{
				SelectingaTile = false;
				gameGrid->ResetHighlights();
				ShowTurn = true;
				CharactersToTake.clear();
			}
		}
	}

	}

	if((CSGD_DirectInput::GetInstance()->KeyPressed(DIK_P)||arcadeP) && !abilityMenu && !ItemMenu && !Command && !SelectingaTile && !Attack && !Movement && !StatsMenu && !abilityTargeting)
	{
		// Play sound to let player know?
		if(playerTurn)
		{
			playerTurn = !playerTurn;
			Turn = !Turn;
			Timer = 0.0f;
			ShowTurn = true;

			if(!playerTurn)
			{
				ai->SetCurrChar(0);
			}

			for(unsigned int i = 0; i < this->Characters.size();i++)
			{
				this->Characters[i]->SetActed(false);
				this->Characters[i]->SetMoved(false);
				this->Characters[i]->UpdateStatusEffects();
			}

			WeatherTime++;
		}
		else
		{
			this->StartActionWindow(42);
		}

	}

	if(WeatherType == 1)
	{
		if(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(SnowSound))
			CSGD_XAudio2::GetInstance()->SFXStopSound(SnowSound);

		WeatherSystem::GetInstance()->ChangeWeather("Rain.xml");
		WeatherType = 0;
		bool found = false;

		vector<string>::iterator iter = ActiveKeys.begin();

		for( ; iter != ActiveKeys.end(); )
		{
			if(iter->find("Rain.xml") == 0)
			{
				found = true;
				iter++;
			}
			else if(iter->find("Snow.xml") == 0)
			{
				iter = ActiveKeys.erase(iter);
			}
			else
				iter++;
		}

		if(found == false  || ActiveKeys.size() == 0)
			ActiveKeys.push_back("Rain.xml");

		CSGD_XAudio2::GetInstance()->SFXPlaySound(RainSound);
	}
	else if(WeatherType == 2)
	{
		if(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(SnowSound))
			CSGD_XAudio2::GetInstance()->SFXStopSound(SnowSound);

		if(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(RainSound))
			CSGD_XAudio2::GetInstance()->SFXStopSound(RainSound);

		WeatherSystem::GetInstance()->ChangeWeather("Sun.xml");
		WeatherType = 0;

		vector<string>::iterator iter = ActiveKeys.begin();

		for( ; iter != ActiveKeys.end(); )
		{
			if(iter->find("Rain.xml") == 0)
			{
				iter = ActiveKeys.erase(iter);
			}
			else if(iter->find("Snow.xml") == 0)
			{
				iter = ActiveKeys.erase(iter);
			}
			else
				iter++;
		}

		CSGD_XAudio2::GetInstance()->SFXPlaySound(sunnyID);
	}
	else if(WeatherType == 3)
	{
		if(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(RainSound))
			CSGD_XAudio2::GetInstance()->SFXStopSound(RainSound);

		WeatherSystem::GetInstance()->ChangeWeather("Snow.xml");
		WeatherType = 0;
		bool found = false;

		vector<string>::iterator iter = ActiveKeys.begin();

		for( ; iter != ActiveKeys.end(); )
		{
			if(iter->find("Snow.xml") == 0)
			{
				found = true;
				iter++;
			}
			else if(iter->find("Rain.xml") == 0)
			{
				iter = ActiveKeys.erase(iter);
			}
			else
				iter++;
		}

		if(found == false || ActiveKeys.size() == 0)
			ActiveKeys.push_back("Snow.xml");

		CSGD_XAudio2::GetInstance()->SFXPlaySound(SnowSound);
	}
}

void GamePlayState::GameRender()
{
	RECT GUItop = {6, 6, 211, 34};
	RECT GUImid = {6, 45, 211, 92};
	RECT GUIbot = {6, 103, 211, 132};

	gameGrid->Render();

	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();

	vector<string>::iterator iter = ActiveKeys.begin();
			
	for( ; iter != ActiveKeys.end(); iter++)
	{	
		if((*iter) != "FireBall.xml" && (*iter) != "TsunamiRight.xml")
		{
			ParticleManager::GetInstance()->Render((*iter));
		}
	}

	if(ShowTurn == true && Timer < 2.0f)
	{
		if(Turn == true)
			Font.Print("Player Turn",100,200,4.0f);
		else if(Turn == false)
			Font.Print("Enemy Turn",100,200,4.0f);
	}

	if(healingShit == true)
	{
		PotRender();
	}

	if(SelectingaTile == true)
	{
		CSGD_TextureManager::GetInstance()->Draw(PanelID, (Game::GetInstance()->GetWinWidth()/2) - 210, 30, 1.3f, 1.7f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		CSGD_TextureManager::GetInstance()->Draw(PanelID, (Game::GetInstance()->GetWinWidth()/2) - 210, 60, 1.3f, 1.7f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		
		RECT right = {(Game::GetInstance()->GetWinWidth()/2)-200, 45, (Game::GetInstance()->GetWinWidth()/2)+50, 90};
		CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
		Font.Print("Character:", (Game::GetInstance()->GetWinWidth()/2)-180, 45, 1.0f);

		if(CharactersToTake[SelectingCount]->GetType() == KNIGHT)
			Font.Print("Knight", (Game::GetInstance()->GetWinWidth()/2) - 60, 45, 1.0f);
		else if(CharactersToTake[SelectingCount]->GetType() == WIZARD)
			Font.Print("Wizard", (Game::GetInstance()->GetWinWidth()/2) - 60, 45, 1.0f);
		else if(CharactersToTake[SelectingCount]->GetType() == ROGUE)
			Font.Print("Rogue", (Game::GetInstance()->GetWinWidth()/2) - 60, 45, 1.0f);
		else if(CharactersToTake[SelectingCount]->GetType() == ARCHER)
			Font.Print("Archer", (Game::GetInstance()->GetWinWidth()/2) - 60, 45, 1.0f);
	}

	Tile* display = gameGrid->ReturnHilightedTile(0);

	if(AImoving == false)
	{

	pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 44, 30, 0.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 44, 72, 0.7f, 1.5f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
	pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 44, 115, 0.7f, 1.5f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

	switch(display->GetTerrainType())
	{
	case GRASS:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40), 30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Grass", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("No Effect", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case DIRT:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Dirt", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("No Effect", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case STONE_FLOOR:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Floor", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("No Effect", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case ROCKS:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Rocks", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("No Effect", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case SNOW:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Snow", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("-1 Move", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case MUD:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Mud", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("-25%", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			Font.Print("Atk & Def", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 45), 125, 1.0f);
			break;
		}
	case WATER:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Water", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("-1 Move", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case SHRUB:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Shrub", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("+25%", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			Font.Print("Defense", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 125, 1.0f);
			break;
		}
	case LAVA:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Lava", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("-50%", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			Font.Print("All Stats", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 45), 125, 1.0f);
			break;
		}
	case TREE:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Tree", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("Obstacle", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case MOUNTIAN:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Mountain", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("Obstacle", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case PILLAR:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Pillar", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("Obstacle", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case STONE_WALL:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Wall", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("Obstacle", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	case CROWD:
		{
			RECT right = {(LONG)((Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 40),30, Game::GetInstance()->GetWinWidth() - 40, (LONG)(Game::GetInstance()->GetWinHeight() * 0.20) + 35};
			CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
			Font.Print("Tile Data:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 30), 35, 1.0f);
			Font.Print("Crowd", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 65, 1.0f);
			Font.Print("Obstacle", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.15)) - 40), 95, 1.0f);
			break;
		}
	};

	}

	char buffer[50];
	if(display->GetCharacter() != nullptr)
	{

		if(AImoving == false)
		{

		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 45, 155, 0.7f, 1.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 45, 185, 0.7f, 2.2f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth() - (Game::GetInstance()->GetWinWidth()*0.17)) - 45, 285, 0.7f, 1.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		//RECT right = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.18)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.223), Game::GetInstance()->GetWinWidth(), (LONG)(Game::GetInstance()->GetWinHeight() * 0.47)};
		//CSGD_Direct3D::GetInstance()->DrawRect(right, 0, 0, 0);
		switch(display->GetCharacter()->GetType())
		{
		case KNIGHT:
			{
					Font.Print("Knight", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 40), 155, 1.0f);
				break;
			}
		case ARCHER:
			{
				Font.Print("Archer", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 40), 155, 1.0f);
				break;
			}
		case ROGUE:
			{
				Font.Print("Rogue", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 40), 155, 1.0f);
				break;
			}
		case WIZARD:
			{
				Font.Print("Wizard", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 40), 155, 1.0f);
				break;
			}
		case BLACK_KNIGHT:
			{
				Font.Print("Black Knight", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 155, 1.0f);
				break;
			}
		};
		Font.Print("HP: ", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 35), 185, 1.0f);
		sprintf_s(buffer, "%d", display->GetCharacter()->GetHP());
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.08)) - 35), 185, 1.0f);
		Font.Print("MP:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 35), 215, 1.0f);
		sprintf_s(buffer, "%d", display->GetCharacter()->GetMP());
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.08)) - 35), 215, 1.0f);
		Font.Print("Damage:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 35), 255, 1.0f);
		sprintf_s(buffer, "%d", (display->GetCharacter()->GetAtk() + display->GetCharacter()->GetWpn()));
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)) - 35), 255, 1.0f);
		Font.Print("Defense:", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 35), 285, 1.0f);
		sprintf_s(buffer, "%d", (display->GetCharacter()->GetDef() + display->GetCharacter()->GetArm()));
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)) - 35), 285, 1.0f);
	

		string status;
		status.append("Status:\n");
		int rectScale = 0;
		if(display->GetCharacter()->GetStatusEffects()->size() >= 1)
		{
			rectScale += display->GetCharacter()->GetStatusEffects()->size();
			vector<StatusEffect*>::iterator iter = display->GetCharacter()->GetStatusEffects()->begin();
			for( ; iter != display->GetCharacter()->GetStatusEffects()->end(); ++iter)
			{
				switch((*iter)->effectType)
				{
				case REINFORCED:
					status.append("Reinforced\n");
					break;
				case HIDDEN:
					status.append("Hiding\n");
					break;
				case ALLERGIES:
					status.append("Allergies\n");
					break;
				case COVERED:
					status.append("Covered\n");
					break;
				case TAUNTED:
					status.append("Taunted\n");
					break;
				case GUARDING:
					status.append("Defending\n");
					break;
				case GUARDING_BRIDGE:
					status.append("Guard Bridge\n");
					break;
				case KNEE_CAPS:
					status.append("Bite Knee Caps\n");
					break;
				};
			}
		}

		if(display->GetCharacter()->GetTileEffects()->size() >= 1)
		{
			rectScale += display->GetCharacter()->GetTileEffects()->size();
			vector<StatusEffect*>::iterator iter = display->GetCharacter()->GetTileEffects()->begin();
			for( ; iter != display->GetCharacter()->GetTileEffects()->end(); ++iter)
			{
				switch((*iter)->effectType)
				{
				case MOVEMENT:
					status.append("-Movement\n");
					break;
				case ATTACK:
					status.append("-Attack\n");
					break;
				case DEFENSE:
					{
						if((*iter)->effectValue < 0)
							status.append("-Defense\n");
						else if((*iter)->effectValue > 0)
							status.append("+Defense\n");
						break;
					}
				};
			}
		}

		if(display->GetCharacter()->GetTileEffects()->size() == 0 && display->GetCharacter()->GetStatusEffects()->size() == 0)
			status.append(" None");

		RECT effects = {40, 32, (LONG)((Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.82)) + 40), (LONG)(((Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.89)) + 32) + (10 * rectScale))};
		CSGD_Direct3D::GetInstance()->DrawRect(effects, 0, 0, 0);
		Font.Print(status.c_str(), 50, 32, 1.0f);

		}
	}

	
	TileManager * tm = TileManager::GetInstance();

	//RECT cursorRect;
	//cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
	//cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
	//cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
	//cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));
	//
	//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,255,0,0);
	//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,255,0,0);
	//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,255,0,0);
	//CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,255,0,0);
	if(abilityTargeting || Attack)
	{
		RECT cursorRect;
		cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+( activeTile->GetX() *tm->GetScale()*tm->GetTileSizeX()))+5;
		cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(activeTile->GetY()*tm->GetScale()*tm->GetTileSizeY()))+5;
		cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()))-10;
		cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()))-10;

		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,0,255,0);
	}
	else if(!this->playerTurn && this->aiTargeting)
	{
		RECT cursorRect;
		
		cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+( aiSelected->GetTile()->GetX() *tm->GetScale()*tm->GetTileSizeX()))+5;
		cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(aiSelected->GetTile()->GetY()*tm->GetScale()*tm->GetTileSizeY()))+5;
		cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()))-10;
		cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()))-10;

		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,0,255,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,0,255,0);

		if(aiTarget != nullptr)
		{
			cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+( aiTarget->GetTile()->GetX() *tm->GetScale()*tm->GetTileSizeX()));
			cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(aiTarget->GetTile()->GetY()*tm->GetScale()*tm->GetTileSizeY()));
			cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
			cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

			CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,		255,0,0);
			CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,255,0,0);
			CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,	255,0,0);
			CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,	255,0,0);
		}
	}
	
	if(playerTurn)
	{
		RECT cursorRect;
		cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
		cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,255,0,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,255,0,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,255,0,0);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,255,0,0);
	}
	else
	{
		RECT cursorRect;
		cursorRect.left = (LONG)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX()));
		cursorRect.top = (LONG)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.bottom = cursorRect.top + (LONG)((tm->GetScale()*tm->GetTileSizeY()));
		cursorRect.right = cursorRect.left + (LONG)((tm->GetScale()*tm->GetTileSizeX()));

		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.right,cursorRect.top,50,50,50);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.bottom,cursorRect.right,cursorRect.bottom,50,50,50);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.left,cursorRect.top,cursorRect.left,cursorRect.bottom,50,50,50);
		CSGD_Direct3D::GetInstance()->DrawLine(cursorRect.right,cursorRect.top,cursorRect.right,cursorRect.bottom,50,50,50);
	}

	pTM->Draw(selectID, (int)(tm->GetPosX()*tm->GetScale()+(cursorX*tm->GetScale()*tm->GetTileSizeX())), (int)(tm->GetPosY()*tm->GetScale()+(cursorY*tm->GetScale()*tm->GetTileSizeY())), tm->GetScale()/2, tm->GetScale()/2, 0, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));

	if(actionWindow || actionWindowTimed)//displaying an action)
	{
		pTM->Draw(PanelID, 200, 30, 1.65f, 0.5f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 200, 40, 1.65f, 1.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		switch(actionWindowEnum)//actionWindowEnum)
		{
		case REINFORCED_CARDBOARD:
			{
				Font.Print("Reinforced Cardboard", 250, 30, 1.0f);
				break;
			}
		case SHIELD_BASH:
			{
				Font.Print("Shield Bash", 300, 30, 1.0f);

				break;
			}
		case COVER:
			{
				Font.Print("Cover", 330, 30, 1.0f);

				break;
			}
		case HIDE:
			{
				Font.Print("Hide", 335, 30, 1.0f);
				break;
			}
		case BACKSTAB:
			{
				Font.Print("Backstab", 315, 30, 1.0f);

				break;
			}
		case INFLICT_ALLERGIES:
			{
				Font.Print("Inflict Allergies", 270, 30, 1.0f);

				break;
			}
		case LIGHTNING_BOLT:
			{
				Font.Print("LIGHTNING BOLT!!!", 240, 30, 1.0f);

				break;
			}
		case FIRE_BALLS:
			{
				Font.Print("Fire Balls", 310, 30, 1.0f);

				break;
			}
		case TSUNAMI:
			{
				Font.Print("Tsunami", 320, 30, 1.0f);

				break;
			}
		case PEROXIDE:
			{
				Font.Print("Peroxide", 315, 30, 1.0f);

				break;
			}
		case MULTI_SHOT:
			{
				Font.Print("Multi-Shot", 305, 30, 1.0f);

				break;
			}
		case SHOOT_HARDER:
			{
				Font.Print("Shoot Harder", 290, 30, 1.0f);

				break;
			}
		case SHOOT_FARTHER:
			{
				Font.Print("Shoot Farther", 290, 30, 1.0f);

				break;
			}
		case TAUNT:
			{
				Font.Print("Taunt", 330, 30, 1.0f);

				break;
			}
		case GUARD_BRIDGE:
			{
				Font.Print("Guard Bridge", 290, 30, 1.0f);

				break;
			}
		case GUARD:
			{
				Font.Print("Guard", 340, 30, 1.0f);

				break;
			}
		case MOVE2:
			{
				Font.Print("Move", 345, 30, 1.0f);

				break;
			}
		case ATTACK2:
			{
				Font.Print("Attack", 340, 30, 1.0f);

				break;
			}
		case HPOTION2:
			{
				Font.Print("Health Potion", 290, 30, 1.0f);

				break;
			}
		case MPOTION2:
			{
				Font.Print("Mana Potion", 300, 30, 1.0f);

				break;
			}
		case INHALER2:
			{
				Font.Print("Inhaler", 340, 30, 1.0f);

				break;
			}
		case 42:
			{
				Font.Print("Action cannot be performed", 215, 30, 1.0f);				

				break;
			}
			
		};

	}

	//CSGD_TextureManager::GetInstance()->Draw(CursorID, (Game::GetInstance()->GetWinWidth()/2), (Game::GetInstance()->GetWinHeight()/2));
	//sprintf_s(buffer, "%d", Characters[0]->GetExp());
	//Font.Print(buffer, (int)(Characters[0]->GetTile()->GetScreenPosX()*gameGrid->GetScale()), (int)(Characters[0]->GetTile()->GetScreenPosY()*gameGrid->GetScale()), 1.0f);

	if(DiceRolled == true)
	{
		RenderDice();
	}
	if(DiceShown == true)
	{
		RenderRoll();
	}

	if(twentyPosX >= -90 || twentyRender)
	{
		RECT tempT;
		tempT.top = 0;
		tempT.left = 0;
		tempT.right = pTM->GetTextureWidth(twentyBMPID);
		tempT.bottom = pTM->GetTextureHeight(twentyBMPID);

		pTM->Draw(twentyBMPID,twentyPosX,50,0.25f,0.25f,&tempT,0.0f,0.0f,0.0f,D3DCOLOR_ARGB(255,255,255,255));
	}

	if(Paused)
	{
		pTM->Draw(PanelID, 210, 30, 1.7f, 1.9f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 210, 70, 1.7f, 2.2f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		
		pTM->Draw(PanelID, 240, 210, 1.2f, 1.7f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 240, 255, 1.2f, 1.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, 240, 295, 1.2f, 1.5f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		//RECT middle = {(LONG)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.69)), (LONG)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.80)), (LONG)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.35)), (LONG)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.45))};
		//CSGD_Direct3D::GetInstance()->DrawRect(middle, 0, 0, 0);
		Font.Print("Paused", (int)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.68)), (int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.95)), 3.0f);
		Font.Print("Resume", (int)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.63)), (int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.65)), 2.0f);
		Font.Print("Exit", (int)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.62)), (int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.55)), 2.0f);

		RECT bottom = {0, (LONG)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.08)), (LONG)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.57)), Game::GetInstance()->GetWinHeight()};
		CSGD_Direct3D::GetInstance()->DrawRect(bottom, 0, 0, 0);
		Font.Print("Turn 0", 10, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);
		Font.Print("Player 1", 110, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);
		Font.Print("Enemy 1", 230, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight() * 0.07)), 1.0f);

		if(Resume)
			CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.66)), (int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.60)));
		else if(!Resume)
			CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth() -(Game::GetInstance()->GetWinWidth()*0.66)), (int)(Game::GetInstance()->GetWinHeight() - (Game::GetInstance()->GetWinHeight()*0.50)));
	}

	if(Command && !Paused && !ItemMenu && !abilityMenu)
	{
		//ECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
		//SGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 320, 0.8f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 346, 0.8f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 446, 0.8f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 515, 0.8f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		Font.Print("Move", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 330, 1.0f);
		Font.Print("Attack", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 370, 1.0f);
		Font.Print("Use Ability", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 410, 1.0f);
		Font.Print("Defend", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 450, 1.0f);
		Font.Print("Use Item", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 490, 1.0f);
		Font.Print("Back", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 530, 1.0f);

		switch(CmndChoice)
		{
		case 0:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 330);
				break;
			}

		case 1:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 370);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 410);
				break;
			}

		case 3:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 450);
				break;
			}
			
		case 4:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 490);
				break;
			}

		case 5:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 530);
				break;
			}
		};
	}

	if(ItemMenu && !Paused && !Command && !abilityMenu)
	{
		//RECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
		//CSGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);

		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 320, 0.8f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 346, 0.8f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 446, 0.8f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45, 515, 0.8f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		sprintf_s(buffer, "%d", HPotions);
		Font.Print("Potion ", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 350, 1.0f);
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)) - 45), 350, 1.0f);
		sprintf_s(buffer, "%d", MPotions);
		Font.Print("Ether ", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 400, 1.0f);
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)) - 45), 400, 1.0f);
		sprintf_s(buffer, "%d", Inhalers);
		Font.Print("Inhaler ", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 450, 1.0f);
		Font.Print(buffer, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.05)) - 45), 450, 1.0f);
		Font.Print("Back", (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.17)) - 45), 500, 1.0f);

		switch(ItemChoice)
		{
		case 0:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 350);
				break;
			}

		case 1:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 400);
				break;
			}

		case 2:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 450);
				break;
			}

		case 3:
			{
				CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)((Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 45), 500);
				break;
			}
		};
	}

	if(abilityMenu && !ItemMenu && !Paused && !Command)
	{
		//RECT cmnd = {(LONG)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.27)),(LONG)(Game::GetInstance()->GetWinHeight() * 0.50), Game::GetInstance()->GetWinWidth(), Game::GetInstance()->GetWinHeight()};
		//CSGD_Direct3D::GetInstance()->DrawRect(cmnd, 0, 0, 0);

		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 70, 320, 1.0f, 2.0f, &GUItop, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 70, 346, 1.0f, 2.3f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 70, 446, 1.0f, 2.0f, &GUImid, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));
		pTM->Draw(PanelID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.20)) - 70, 515, 1.0f, 2.0f, &GUIbot, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255,255,255,255));

		switch (this->activeTile->GetCharacter()->GetType())
		{
		case WIZARD:
			{
				Font.Print("L. Bolt!! 5",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 330, 1.0f);
				Font.Print("Fire Ball 10",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 380, 1.0f);
				Font.Print("Tsunami 60",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 420, 1.0f);
				Font.Print("Peroxide 50",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 470, 1.0f);
				Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 520, 1.0f);

				break;
			}
		case KNIGHT:
			{
				Font.Print("Reinforced Armor",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-23, 330, 1.0f);
				Font.Print("Shield Bash",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 380, 1.0f);
				Font.Print("Cover",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 420, 1.0f);
				Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 470, 1.0f);

				break;
			}

		case ARCHER:
			{
				Font.Print("Multi-Shot",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 330, 1.0f);
				Font.Print("Shoot Harder",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 380, 1.0f);
				Font.Print("Shoot Farther",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 420, 1.0f);
				Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 470, 1.0f);

				break;
			}
		case ROGUE:
			{
				Font.Print("Hide",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 330, 1.0f);
				Font.Print("Backstab",			(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 380, 1.0f);
				Font.Print("Inflict Allergies",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 420, 1.0f);
				Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 470, 1.0f);

				break;
			}
		case BLACK_KNIGHT:
			{
				Font.Print("Taunt",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 330, 1.0f);
				Font.Print("Bite Knee Caps",	(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 380, 1.0f);
				Font.Print("Guard Bridge",		(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 420, 1.0f);
				Font.Print("Back",				(int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.25))-10, 470, 1.0f);

				break;
			}
		};
		CSGD_TextureManager::GetInstance()->Draw(CursorID, (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.27))-22, 330+(50*abilitySelection));
	}

	if(abilityTargeting)
		Font.Print("Press Backspace To Return", 10, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.07)),1.0f);

	if(Movement)
		Font.Print("Press Backspace To Return", 10, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.07)),1.0f);

	if(Attack)
		Font.Print("Press Backspace To Return", 10, (int)(Game::GetInstance()->GetWinHeight()- (Game::GetInstance()->GetWinHeight()*0.07)),1.0f);

	if(!abilityMenu && !ItemMenu && !Paused && !Attack && !Movement  && !Command && !SelectingaTile && playerTurn && !abilityTargeting)
		Font.Print("Press P To End Turn", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.95)),(int)(Game::GetInstance()->GetWinHeight()*0.90),1.0f);

	if(SelectingaTile)
	{
		Font.Print("Press Enter to Place", Game::GetInstance()->GetWinWidth()/2 - 100, Game::GetInstance()->GetWinHeight()/2 + 50, 2.0f, 255, 255, 255);
		Font.Print("Your Characters on", Game::GetInstance()->GetWinWidth()/2 - 100, Game::GetInstance()->GetWinHeight()/2 + 100, 2.0f, 255, 255, 255);
		Font.Print("Highlighted Tiles!", Game::GetInstance()->GetWinWidth()/2 - 100, Game::GetInstance()->GetWinHeight()/2 + 150, 2.0f, 255, 255, 255);
	}
}

// function for loading a xml to apply equipment to characters
void GamePlayState::LoadEquipment()
{
	vector<Item*>::iterator inv = Inventory.begin();

	for(; inv != Inventory.end();inv++)
	{
		switch((*inv)->GetID())
		{
		case KN_ARM:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}

				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case KN_WPN:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == KNIGHT && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case WIZ_WPN:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case WIZ_ARM:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == WIZARD && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case ARCH_WPN:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case ARCH_ARM:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == ARCHER && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case RG_WPN:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		case RG_ARM:
			{
				vector<BaseCharacter*>::iterator iter;
				iter = selectFrom.begin();
				for( ; iter != selectFrom.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				iter = CharactersToTake.begin();
				for( ; iter != CharactersToTake.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE)
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				
				iter = Characters.begin();
				for( ; iter != Characters.end(); ++iter)
				{
					if((*iter)->GetType() == ROGUE && (*iter)->IsPlayer())
						(*inv)->ApplyEffect((*inv)->GetID(), *iter);
				}
				break;
			}
		};
	}
}

void GamePlayState::BattleWindowFade(void)
{
	CSGD_TextureManager::GetInstance()->Draw(FadeWindowImg, FadeWindow.left, FadeWindow.top, (float)Game::GetInstance()->GetWinWidth()/CSGD_TextureManager::GetInstance()->GetTextureWidth(FadeWindowImg), 
											 (float)Game::GetInstance()->GetWinHeight()/CSGD_TextureManager::GetInstance()->GetTextureHeight(FadeWindowImg), 
											 &FadeWindow, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(200, 255, 255, 255));

	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();
}

void GamePlayState::BattleWindow()
{
	if(CurAttacker == nullptr || CurDefender == nullptr)
		return;

	int AtkerType = 0;
	int DefendType = 0;

	AtkerType = CurAttacker->GetTile()->GetCharacter()->GetType();
	DefendType = CurDefender->GetTile()->GetCharacter()->GetType();

	myManager->Render(CurAttacker, Game::GetInstance()->GetWinWidth()/2 - 200, Game::GetInstance()->GetWinHeight()/2 + 50, 10.0f, false);

	myManager->Render(CurDefender, Game::GetInstance()->GetWinWidth()/2 + 200, Game::GetInstance()->GetWinHeight()/2 + 75, 10.0f, false);


	vector<string>::iterator iter = ActiveKeys.begin();

	for( ; iter != ActiveKeys.end(); iter++)
	{
		if((*iter) == "FireBall.xml" || (*iter) == "TsunamiRight.xml")
		{
			if(DiceShown == true)
				ParticleManager::GetInstance()->Render((*iter));
		}
	}

	if(AtkTypeStorage != -1)
	{
		switch(AtkTypeStorage)
		{
		case LIGHTNING_BOLT:
			{
				int pos = 0;

				if(DiceShown == true)
				{
					pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);
				
					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(TennisballID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(tennisID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos>=350)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boltID);
						playVoice = false;
					}
				}
			}
			break;

		case MULTI_SHOT:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 230, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 260, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;

		case FIRE_BALLS:
			{
				if(DiceRolled == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2);

					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(fireCrackerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos>= 410)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(fireID);
						playVoice = false;
					}

					if(!SpellHit && !(CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(throwID)) && pos >= 475)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(crackerID);
						SpellHit = true;
					}
				}
				if(SpellHit && DiceShown == true)
					{
						if(!fbHurt)
						{
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(khurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								}
								break;
							case WIZARD:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(whurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								}
								break;
							case ARCHER:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(ahurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								}
								break;
							case ROGUE:
								{
									if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(rhurtID))
										CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								}
								break;
							};
							playVoice = false;
						}
						fbHurt = true;
					}
			}
			break;

		case TSUNAMI:
			{
				if(DiceRolled == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2);

					if(pos <= 500)
						CSGD_TextureManager::GetInstance()->Draw(WaterBalloonID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed2), 200, 2.0f, 2.0f,
											  nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255));
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(throwID);
						Throw = false;
					}
					else if(playVoice && !Throw && pos >=350)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(waterID);
						playVoice = false;
					}
				}
				if(!SpellHit && DiceShown == true)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(splashID);
					SpellHit = true;
					playVoice = true;
					switch(CurDefender->GetType())
					{
					case KNIGHT:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
						break;
					case WIZARD:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
						break;
					case ARCHER:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
						break;
					case ROGUE:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
						break;
					};
					playVoice = false;
				}
			}
			break;

		case SHOOT_HARDER:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;

		case SHOOT_FARTHER:
			{
				if(DiceShown == true)
				{
					int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

					if(pos <= 500)
					{
						CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
							nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
					}
					else
					{
						if(!SpellHit)
						{
							CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
							SpellHit = true;
							playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
						}
					}
					if(Throw)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
						Throw = false;
					}
				}
			}
			break;
		}
	}
	else
	{
		if(CurAttacker->GetType() == ARCHER)
		{
			if(DiceShown == true)
			{
				int pos = (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed);

				if(pos <= 500)
				{
					CSGD_TextureManager::GetInstance()->Draw(PlungerID, (int)((Game::GetInstance()->GetWinWidth()/2 - 100)+Shotspeed), 200, 1.0f, 1.0f,
						nullptr, 32.0f, 64.0f, D3DXToRadian(-90.0f), D3DCOLOR_XRGB(255, 255, 255));
				}
				else
				{
					if(!SpellHit)
					{
						CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
						SpellHit = true;
						playVoice = true;
							switch(CurDefender->GetType())
							{
							case KNIGHT:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
								break;
							case WIZARD:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
								break;
							case ARCHER:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
								break;
							case ROGUE:
								CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
								break;
							};
							playVoice = false;
					}
				}
				if(Throw)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(boingID);
					Throw = false;
				}
			}
		}
		else
		{
			if(DiceShown == true)
			{
				if(Throw)
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(swingID);
					Throw = false;
				}

				if(!SpellHit && !Throw && !CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(swingID))
				{
					CSGD_XAudio2::GetInstance()->SFXPlaySound(thudID);
					SpellHit = true;
					playVoice = true;
					switch(CurDefender->GetType())
					{
					case KNIGHT:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(khurtID);
						break;
					case WIZARD:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(whurtID);
						break;
					case ARCHER:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(ahurtID);
						break;
					case ROGUE:
						CSGD_XAudio2::GetInstance()->SFXPlaySound(rhurtID);
						break;
					};
					playVoice = false;
				}
			}
		}
	}
}
void GamePlayState::HighlightMove()
{
	TileManager * tm = TileManager::GetInstance();

	if(Movement)
	{
		for(int x = 0; x < tm->GetSizeX();x++)
		{
			for(int y = 0 ; y < tm->GetSizeY();y++)
			{

				int ert;
				if(x == 2 && y == 3)
					ert = 0;


				if(!this->CheckMoveToTile(activeTile,gameGrid->GetTile(x,y)))
					continue;
					//tm->GetTile(x,y)->HighlightTile(true,255,0,0,150);
				else
					tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);

				
			}
		}
	}
}

void GamePlayState::HighlightAction(bool enemy,int range)
{
	TileManager * tm = TileManager::GetInstance();

	for(int x = 0; x < tm->GetSizeX();x++)
	{
		for(int y = 0 ; y < tm->GetSizeY();y++)
		{
			int xR = 0,yR = 0,distance = 0;
			xR = activeTile->GetX() - x;
			yR = activeTile->GetY() - y;

			if(xR < 0)
				xR *= -1;
			if(yR < 0)
				yR*=-1;

			distance = xR + yR;

			if(distance > range)
				continue;
			else
			{

				if(abilitySelection == 2 && activeTile == tm->GetTile(x,y))
					continue;

				if(tm->GetTile(x,y)->GetObstacle() || tm->GetTile(x,y)->GetCharacter() == nullptr)
					continue;
					//tm->GetTile(x,y)->HighlightTile(true,255,0,0,150);
				else
				{
					if(enemy && tm->GetTile(x,y)->GetCharacter()->IsPlayer() != activeTile->GetCharacter()->IsPlayer())
						tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);
					else if(!enemy && tm->GetTile(x,y)->GetCharacter()->IsPlayer() == activeTile->GetCharacter()->IsPlayer())
						tm->GetTile(x,y)->HighlightTile(true,0,255,0,100);						
				}
			}
		}
	}
}


void GamePlayState::ArcadeInput()
{
	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;

	CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();

	if(di->JoystickGetLStickDirPressed(DIR_UP,0))
	{
		arcadeUp = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_DOWN,0))
	{
		arcadeDown = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_LEFT,0))
	{
		arcadeLeft = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_RIGHT,0))
	{
		arcadeRight = true;
	}

	if(di->JoystickButtonPressed(0,0))
	{
		arcadeEnter = true;
	}

	if(di->JoystickButtonPressed(1,0))
	{
		arcadeBackspace = true;
	}

	if(di->JoystickButtonPressed(2,0))
	{
		arcadeP = true;
	}

	if(di->JoystickButtonPressed(3,0))
	{
		arcadeShift = true;
	}

	if(di->JoystickButtonPressed(4,0))
	{
		arcadePlus = true;
	}

	if(di->JoystickButtonPressed(5,0))
	{
		arcadeMinus = true;
	}

	if(di->JoystickButtonPressed(6,0))
	{
		arcadeEscape = true;
	}
}

void GamePlayState::StartActionWindow(int i)
{
	this->actionWindow = true;
	actionWindowTimer = 0.0f;
	actionWindowEnum = i;

	if(i == 42)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(this->errorID);
	}

	if(i == FIRE_BALLS)
	{
		fbHurt = false;
	}
	Throw = true;
	SpellHit = false;
	playVoice = true;
}


bool GamePlayState::CheckMoveToTile(Tile* curTile, Tile* tar, vector<Tile*>* v)
{
	Tile * currentTile = curTile;
	Tile * target= tar;

	if(currentTile == target || target->GetObstacle() || target->GetCharacter() != nullptr)
		return false;

	int xR = 0,yR = 0,distance = 0;
	xR = currentTile->GetX() - target->GetX();
	yR = currentTile->GetY() - target->GetY();

	if(xR < 0)
		xR *= -1;
	if(yR < 0)
		yR*=-1;

	distance = xR + yR;

	if(distance > currentTile->GetCharacter()->GetMov())
		return false;
	else
	{

		int sX,sY,bX,bY;
		Tile* closestX = nullptr;
		Tile* closestY = nullptr;
		bool startX = true;

		if(currentTile->GetX() > target->GetX())
		{
			sX = target->GetX();
			bX = currentTile->GetX();
			closestX = gameGrid->GetTile(currentTile->GetX()-1,currentTile->GetY());
		}
		else
		{
			sX = currentTile->GetX();
			bX = target->GetX();
			if(currentTile->GetX() < target->GetX())
				closestX = gameGrid->GetTile(currentTile->GetX()+1,currentTile->GetY());

		}
		if(currentTile->GetY() > target->GetY())
		{
			sY = target->GetY();
			bY = currentTile->GetY();
			closestY = gameGrid->GetTile(currentTile->GetX(),currentTile->GetY()-1);

		}
		else 
		{
			sY = currentTile->GetY();
			bY = target->GetY();
			if(currentTile->GetY() < target->GetY())
				closestY = gameGrid->GetTile(currentTile->GetX(),currentTile->GetY()+1);

		}

		if(closestX != nullptr && !closestX->GetObstacle() && closestX->GetCharacter() == nullptr && closestX->GetTerrainType() != LAVA)
			startX = true;
		else if(closestY != nullptr && !closestY->GetObstacle() && closestY->GetCharacter() == nullptr && closestY->GetTerrainType() != LAVA)
			startX = false;
		else if(closestX != nullptr && !closestX->GetObstacle()&& closestX->GetCharacter() == nullptr)
			startX = true;
		else if(closestY != nullptr && !closestY->GetObstacle()&& closestY->GetCharacter() == nullptr)
			startX = false;
		else
			return false;

		if(startX && xR == 0)
			startX = false;
		else if(!startX && yR == 0)
			startX = true;

		vector<Tile*> tiles;
		tiles.clear();
		
		if(startX && closestX != nullptr)
			tiles.push_back(closestX);
		else if(!startX && closestY != nullptr)
			tiles.push_back(closestY);

		currentTile = tiles[0];

		if(currentTile->GetObstacle() || currentTile->GetCharacter() != nullptr)
		{
			tiles.clear();
			if(startX)
				tiles.push_back(closestY);
			else
				tiles.push_back(closestX);

			currentTile = tiles[0];
		}

		for(int i = 0; i < distance;i++)
		{
			Tile * nextClosestX;
			Tile * nextClosestY;

			if(currentTile == target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

			if(tiles[i] == nullptr)
				break;

			if(sX == target->GetX())
			{
				if(tiles[i]->GetX()-1<0)
				{
					break;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()-1,tiles[i]->GetY());
			}
			else

			{

				if(tiles[i]->GetX()+1>gameGrid->GetSizeX())
				{
					break;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()+1,tiles[i]->GetY());
			}
			if(sY == target->GetY())
			{
				if(tiles[i]->GetY()-1<0)
				{
					break;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()-1);
			}
			else
			{
				if(tiles[i]->GetY()+1>gameGrid->GetSizeY())
				{
					break;
				}
				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()+1);
			}

			if(tiles[i]->GetX() == target->GetX())
			{
				if(nextClosestY->GetObstacle() || nextClosestY->GetCharacter() != nullptr)
				{
					break;
				}
				else
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
			}
			else if(tiles[i]->GetY() == target->GetY())
			{
				if(nextClosestX->GetObstacle() || nextClosestX->GetCharacter() != nullptr)
				{
					break;
				}
				else
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
			}
			else
			{
				if(nextClosestX->GetTerrainType() != LAVA && nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetTerrainType() != LAVA && nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else if(nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else
					break;
			}

			if(currentTile = target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

		}
		///////////////////////////////////////////////////////////////////////

		if(startX)
			startX = false;
		else
			startX = true;

		tiles.clear();
		
		if(startX)
			tiles.push_back(closestX);
		else
			tiles.push_back(closestY);

		currentTile = tiles[0];

		if(tiles[0] == nullptr)
			return false;

		if(currentTile->GetObstacle() || currentTile->GetCharacter() != nullptr)
		{
			tiles.clear();
			if(startX)
				tiles.push_back(closestY);
			else
				tiles.push_back(closestX);

			currentTile = tiles[0];
		}

		for(int i = 0; i < distance;i++)
		{
			if(tiles[i] == nullptr)
				return false;

			Tile * nextClosestX;
			Tile * nextClosestY;

			if(currentTile == target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}
			if(sX == target->GetX())
			{
				if(tiles[i]->GetX()-1<0)
				{
					return false;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()-1,tiles[i]->GetY());
			}
			else
			{
				if(tiles[i]->GetX()+1>gameGrid->GetSizeX())
				{
					return false;
				}

				nextClosestX = gameGrid->GetTile(tiles[i]->GetX()+1,tiles[i]->GetY());
			}
			if(sY == target->GetY())
			{
				if(tiles[i]->GetY()-1<0)
				{
					return false;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()-1);
			}
			else
			{
				if(tiles[i]->GetY()+1>gameGrid->GetSizeY())
				{
					return false;
				}

				nextClosestY = gameGrid->GetTile(tiles[i]->GetX(),tiles[i]->GetY()+1);
			}

			if(tiles[i]->GetX() == target->GetX())
			{
				if(nextClosestY->GetObstacle() || nextClosestY->GetCharacter() != nullptr)
				{
					return false;
				}
				else
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
			}
			else if(tiles[i]->GetY() == target->GetY())
			{
				if(nextClosestX->GetObstacle() || nextClosestX->GetCharacter() != nullptr)
				{
					return false;
				}
				else
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
			}
			else
			{
				if(nextClosestX->GetTerrainType() != LAVA && nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetTerrainType() != LAVA && nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else if(nextClosestX->GetCharacter() == nullptr && !nextClosestX->GetObstacle())
				{
					tiles.push_back(nextClosestX);
					currentTile = nextClosestX;
					continue;
				}
				else if(nextClosestY->GetCharacter() == nullptr && !nextClosestY->GetObstacle())
				{
					tiles.push_back(nextClosestY);
					currentTile = nextClosestY;
					continue;
				}
				else
					return false;
			}

			if(currentTile = target)
			{
				if(v != nullptr)
					(*v) = tiles;
				return true;
			}

		}

		if(currentTile = target)
		{
			if(v != nullptr)
				(*v) = tiles;
			return true;
		}
	}
	return true;
}

void GamePlayState::ClearDiceVectors(void)
{
	AtkRolls.clear();
	ARolls.clear();
	DefRolls.clear();
	DRolls.clear();
}